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:
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
:p\d*\b\s=\s'[\w\.]+'
) or,: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\.]
eg [\w\.\?]
would search for word characters, the dot, and a question mark
example: http://regexr.com?2uf6v
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.