Wednesday 15 January 2014

regex - Java String.split() splitting every character instead of given regular expression -


I have a string that I want to divide into an array:

SEQUENCEï ¼ ?? 1Aa ???? 2Ba ???? 3C

I tried the following regular expression:

((*. * \ S) | ([\ X {2192}] *))

  1. \ X {2192} Aero Mark 2 is. There is a place after the colon, I used it as a reference to match the first part   

and it works in the testers (pattern in OSX) Enter image details here

but it divides this string into: < How do I get the following:?

[, 1, a, 2, b, 3, c]

A, 2B, 3C]

This test code is:

  string str = "SEQUENCEï¼" ?? 1A "??? ??? -3C "; // Note that colon system.out.println (Arrays.toString (str.split (" (. * \\ s) | ([\\ x {2192}] *) after an extra space As stated in the post of Richard Seats, the main problem with regex is that it should be that 

< Use div code = "post-text" itemprop = "text">

+ instead of + Additionally, your résx should be further improved. Instead of \\ x {2192} , use \ u2192 and because it is a You do not need to keep it in a character square ( [...] ), you can use directly \ u2192 + . / Li>

  • In addition, because binds more than | . * \\ s and \ u2192 + , you will not need it there Either parentheses, your last expression is simply . * \\ s | \ u2192 + ".

  • No comments:

    Post a Comment