Skip to content

Instantly share code, notes, and snippets.

@thbighead
Last active June 11, 2019 18:56
Show Gist options
  • Save thbighead/8aa69170d538a4f8479e903f7659cea5 to your computer and use it in GitHub Desktop.
Save thbighead/8aa69170d538a4f8479e903f7659cea5 to your computer and use it in GitHub Desktop.
Regex to remove selected columns in a SQL query which have dynamic alias pointed by [anythinghere] flags
<?php
preg_replace('/(SELECT\s*\S*\s+\[[^\[\]]*\]|([a-zA-Z]*\(.*)?,\s*\S*\s+\[[^\[\]]*\])/', '', $input_lines);
@thbighead
Copy link
Author

You just got to be careful with the remaining query, as it can remove the SELECT and keep a comma into it's very beginning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment