0

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:

VALUES (XXX, 

As an example:

VALUES (25, 
VALUES (101, 
VALUES (55, 

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!

Update

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

enter image description here

5
  • Do you want to replace VALUES (XXX, with empty string Commented May 13, 2016 at 4:39
  • You might want to put your table structure. Commented May 13, 2016 at 4:40
  • Oops... Maybe an example of what I am looking for would help. Please check the OP. Commented May 13, 2016 at 4:44
  • I have deleted my answer as not relevant Commented May 13, 2016 at 4:45
  • This is a link to supported SSMS regex commands: msdn.microsoft.com/en-AU/library/ms174214.aspx Commented May 13, 2016 at 4:55

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

SSMS has a limited regex syntax, so {1,3} do not work. (Tested in SSMS 2014)
Ah right... Haven't worked with SMSS' dodgy version of regex before. Updated to use # instead
Bam.. that got it. Thanks Greg!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.