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:

  1. '
  2. stack overflow
  3. '

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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -