Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Regex: matching anything between single quotes (except single quotes) [duplicate]

How do I match anything between single quotes? I need to match all attribute = 'some value' statements within a WHERE clause of queries. I tried:

= '(.+)'

But that doesn't work: somehow messes up all single quotes and matches.

If anyone could help me out it'd be much appreciated!

like image 388
user2999349 Avatar asked May 26 '17 16:05

user2999349


1 Answers

Try:

= '([^']*)'

Meaning you want anything/everything from = ' that isn't a single quote up to a single quote.

Python example:

import re

text = "attribute = 'some value'"
match = re.search("= '([^']*)'", text)
print(match.group(1))

To read more about that, it is called a negated character class: https://www.regular-expressions.info/charclass.html

like image 174
sniperd Avatar answered Nov 15 '22 09:11

sniperd