Quantcast
Viewing all articles
Browse latest Browse all 14

Answer by Brent Writes Code for What is a word boundary in regex?

Check out the documentation on boundary conditions:

http://java.sun.com/docs/books/tutorial/essential/regex/bounds.html

Check out this sample:

public static void main(final String[] args)    {        String x = "I found the value -12 in my string.";        System.err.println(Arrays.toString(x.split("\\b-?\\d+\\b")));    }

When you print it out, notice that the output is this:

[I found the value -, in my string.]

This means that the "-" character is not being picked up as being on the boundary of a word because it's not considered a word character. Looks like @brianary kinda beat me to the punch, so he gets an up-vote.


Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>