find all text contained in single quotes (characters, numbers, special characters)
I am trying to parse this string:
:p0 = 'R' [Type: String (0)], :p1 = 'Y' [Type: String (0)], :p2 = 'HBP00' [Type: String (0)], :p3 = 'MAG.PF'
and I've come up with this expression which works quite well for me:
:p\d*\b\s=\s'\w{1,}'
Basically I am trying to match all the parameters and the values:
- :p0 = 'R'
- :p1 = 'Y'
- :p2 = 'HBP00' 开发者_开发百科
- :p3 = 'MAG.PF'
but I've noticed the expression doesn't work on :p3 cause of the dot, I reckon.
I don't seem to be able to find a way to get all the text contained in single quotes.Thanks for your help.
UPDATE:
I've mixed some information I got here and the one which works for me seems to be:
:p\d*\s=\s'[^']+'
I don't know c# regex syntax very well, but you should either
- include the "." character (something like
:p\d*\b\s=\s'[\w\.]+'
) or, - accept any character excluded single quotes (something like
:p\d*\b\s=\s'[^']+'
)
Simply use this pattern:
'([\w.]+)'
Demo: http://regexhero.net/tester/?id=89309902-4eac-4975-97bc-9c73640ee81f
Try this regex:
:p\d*\b\s=\s'[\w\.]{1,}'
That will include the . character. If you need to expand the expression to include more characters try adding them between the brackets.
For the example above: :p\d*\b\s=\s'[\w\.]{1,}'
should do the trick. Instead of looking for only word characters in between the single quotes, this looks for word characters & the "dot" character. If you need to search for additional special characters, you can add them to the square bracket section [\w\.]
e.g. [\w\.\?]
would search for word characters, the dot, and a question mark
example: http://regexr.com?2uf6v
精彩评论