StealthRT StealthRT - 9 months ago 53
SQL Question

SQL Server 2012 regex finding match

I am using SQL Server Management Studio and need to find and replace some very large database data in a query.

The format I am needing to remove is:


As an example:

VALUES (101,

I can not seem to find a regex in order to do this in SQL find and replace. And I am not very good at trying to make a regex match pattern....

Any help would be great!


Sorry what I meant is that I am using the Find and replace under the Edit menu:

enter image description here


Without more detail about exactly how you're using this regex it is difficult to be sure if this will help or not, but a regex which would match any of those lines would be:

VALUES \([0-9]+,

The 'VALUES (' bit should just match that as a string (the backslash before the open bracket is so your regex engine knows it is part of the string, and not part of the instructions about searching). The [0-9] bit says that any digit from 0-9 is valid, and the + bit says there needs to be at least one digit. You might also want a ^ at the start to indicate it is the start of a line, depending on your use-case. Note that this will match any number of digits after the bracket, and before the final comma.