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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -