简体   繁体   中英

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'[^']+' )

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM