Reputation: 13545
i want a pattern to match below strings :
count="2"
count = "2"
count = "2"
count='2'
count = '2'
count = '2'
count=2
count = 2
count = 2
Upvotes: 0
Views: 174
Reputation: 138137
It isn't too clear what should the pattern not match, but you may be looking for something like this:
count\s*=\s*(["']?)\d+\1
That regex will allow matching quotes (or no quotes) around a number. \1
matches the same thing the first captured group (["']?
) matched before: "
, '
, or nothing, so it wouldn't allow mixed quotes. (?:"\d+"|'\d+'|\d+)
would have worked similarly.
You may want a better definition of strings or numbers, for example:
count\s*=\s*(?:"(?:[^"\n\r\\]|\\.)*"|'(?:[^'\n\r\\]|\\.)*'|\d+)
The regex allows strings with escaped characters an no new-lines, or integer literals.
Upvotes: 4