java - Why this Regular Expression doesn't work? -
i have regular expression extract 2 tokens, delimiters ['] , words between apostrophes 'stack overflow'. question is, why regular expression doesn't work?
regex:
(['])|'([^']*)'
here link explain it: regular expression
only works extracting apostrophes but, words between apostrophes no.
note: need extract apostrophe , word between apostrophe separately 'stack overflow'.
the result like:
- '
- stack overflow
- '
greetings.
your regex says match either single quote or content between quotes, it's exclusive or way have it. each of them capture group use regex:
(')([^']*)(')
to first quote, that's not quote last quote
Comments
Post a Comment