Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use zero-width matching assertions:</p> <pre><code> String str = "la$le\\$li$lo"; System.out.println(java.util.Arrays.toString( str.split("(?&lt;!\\\\)\\$") )); // prints "[la, le\$li, lo]" </code></pre> <p>The regex is essentially</p> <pre><code>(?&lt;!\\)\$ </code></pre> <p>It uses negative lookbehind to assert that there is not a preceding <code>\</code>.</p> <h3>See also</h3> <ul> <li><a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow noreferrer">regular-expressions.info/Lookarounds</a></li> </ul> <hr> <h3>More examples of splitting on assertions</h3> <p>Simple sentence splitting, keeping punctuation marks:</p> <pre><code> String str = "Really?Wow!This.Is.Awesome!"; System.out.println(java.util.Arrays.toString( str.split("(?&lt;=[.!?])") )); // prints "[Really?, Wow!, This., Is., Awesome!]" </code></pre> <p>Splitting a long string into fixed-length parts, using <code>\G</code></p> <pre><code> String str = "012345678901234567890"; System.out.println(java.util.Arrays.toString( str.split("(?&lt;=\\G.{4})") )); // prints "[0123, 4567, 8901, 2345, 6789, 0]" </code></pre> <p>Using a lookbehind/lookahead combo:</p> <pre><code> String str = "HelloThereHowAreYou"; System.out.println(java.util.Arrays.toString( str.split("(?&lt;=[a-z])(?=[A-Z])") )); // prints "[Hello, There, How, Are, You]" </code></pre> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/2406633/can-you-use-zero-width-matching-regex-in-string-split">Can you use zero-width matching regex in String split?</a></li> <li><a href="https://stackoverflow.com/questions/2734977/backreferences-in-lookbehind">Backreferences in lookbehind</a></li> <li><a href="https://stackoverflow.com/questions/2559759/how-do-i-convert-camelcase-into-human-readable-names-in-java">How do I convert CamelCase into human-readable names in Java?</a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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