regex - Java - Split string based on space and single quote but ignore two single quotes -


i want split string using space , single quote. 2 single quotes should ignored.

input:

name eq 'a''b' 

output should be:

name  eq  a''b 

i tried use

[^\\s\"(?<!')'(?!')]+|\"[^\"]*\"|(?<!')'(?!')[^(?<!')'(?!')]*(?<!')'(?!')" 

but not work.

the following 1 should suit needs:

'(?:[^']|'')+'|[^ ]+ 

regular expression visualization

debuggex demo


java example:

string input = "foobar foo bar 'foobar' 'foo bar' 'foo''bar'"; pattern pattern = pattern.compile("'(?:[^']|'')+'|[^ ]+"); matcher matcher = pattern.matcher(input); while (matcher.find()) {     string match = matcher.group();     system.out.println(match); } 

ideone demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -