Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It could probably be done in a single regex if there is no nesting.<br> There is a concept of delimeters roughly defined, and it is possible to 'bias'<br> those rules to get a better outcome.<br> It all depends on what rules are set forth. This regex takes into account<br> three possible scenario's in order;</p> <ol> <li>Valid Pair </li> <li>Invalid Pair (with bias) </li> <li>Invalid Single</li> </ol> <p>It also doesen't parse "" beyond end of line. But it does do multiple<br> lines combined as a single string. To change that, remove <code>\n</code> where you see it. </p> <hr> <p>global context - raw find regex<br> <strong>shortened</strong></p> <pre><code>(?:("[a-zA-Z0-9\p{Punct}][^"\n]*(?&lt;=[a-zA-Z0-9\p{Punct}])")|(?&lt;![a-zA-Z0-9\p{Punct}])"([^"\n]*)"(?![a-zA-Z0-9\p{Punct}])|") </code></pre> <p>replacement grouping</p> <pre><code>$1$2 or \1\2 </code></pre> <p>Expanded raw regex: </p> <pre><code>(?: // Grouping // Try to line up a valid pair ( // Capt grp (1) start " // " [a-zA-Z0-9\p{Punct}] // 1 of [a-zA-Z0-9\p{Punct}] [^"\n]* // 0 or more non- [^"\n] characters (?&lt;=[a-zA-Z0-9\p{Punct}]) // 1 of [a-zA-Z0-9\p{Punct}] behind us " // " ) // End capt grp (1) | // OR, try to line up an invalid pair (?&lt;![a-zA-Z0-9\p{Punct}]) // Bias, not 1 of [a-zA-Z0-9\p{Punct}] behind us " // " ( [^"\n]* ) // Capt grp (2) - 0 or more non- [^"\n] characters " // " (?![a-zA-Z0-9\p{Punct}]) // Bias, not 1 of [a-zA-Z0-9\p{Punct}] ahead of us | // OR, this single " is considered invalid " // " ) // End Grouping </code></pre> <p>Perl testcase (don't have Java) </p> <pre><code>$str = ' string1=injunct! alter ego." string2=successor "alter ego" single employer "a" free" proceeding "citation assets" '; print "\n'$str'\n"; $str =~ s / (?: ( "[a-zA-Z0-9\p{Punct}] [^"\n]* (?&lt;=[a-zA-Z0-9\p{Punct}]) " ) | (?&lt;![a-zA-Z0-9\p{Punct}]) " ( [^"\n]* ) " (?![a-zA-Z0-9\p{Punct}]) | " ) /$1$2/xg; print "\n'$str'\n"; </code></pre> <p>Output </p> <pre><code>' string1=injunct! alter ego." string2=successor "alter ego" single employer "a" free" proceeding "citation assets" ' ' string1=injunct! alter ego. string2=successor "alter ego" single employer "a" free proceeding "citation assets" ' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload