3

OK, so this is what I'm trying to do :

  • I've got a complete SQL script
  • Some of the 's inside the values have not been properly escaped
  • e.g. if we have 'children's shoes', I want to replace it with 'children\'s shoes'

So, any suggestions? (I've tried various workarounds but I don't seem to be able to get it right...)


UPDATE:

  • '.+?' sure matches the values - but how do I match the 'ss within the values?

  • Here's a RegExr example of what I'm trying to match : http://regexr.com?368bo


UPDATE II :

OK, I think I'll go with [a-z]'s. It seems like it's capturing what I need. And replace with $1\'s.

12
  • 1
    Since you tagged your question with regex, what was your last regex attempt? Commented Sep 7, 2013 at 11:05
  • @Jerry I've tried something like : '.+?('s).+?' but it seems to be too... greedy Commented Sep 7, 2013 at 11:06
  • @Downvoters What's the issue with the question? I've happily replied LOTS and LOTS of times on Regex-related questions, and one time I need some assistance I get downvoted? What is not clear about my requirements? :S Commented Sep 7, 2013 at 11:07
  • Don't do this. Ever. If the SQL statement is already invalid, go one step back and escape the parameters when you create the statement. It's not possible to do what you ask for. Commented Sep 7, 2013 at 11:09
  • How to know whether quoted string is not ending with 2nd quote i.e. 'children' Commented Sep 7, 2013 at 11:10

1 Answer 1

3

Match this regex:

('[^']*)'s([^']*') 

And replace with:

$1\'s$2 

Live Demo: http://regexr.com?368bu

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

1 Comment

Perfect. You nailed it! Thanks a lot! :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.