Find ASCII "arrows" in text

Posted by ulver on Stack Overflow See other posts from Stack Overflow or by ulver
Published on 2009-07-25T21:09:05Z Indexed on 2010/04/06 1:53 UTC
Read the original article Hit count: 321

Filed under:
|

I'm trying to find all the occurrences of "Arrows" in text, so in

"<----=====><==->>"

the arrows are:

"<----", "=====>", "<==", "->", ">"

This works:

 String[] patterns = {"<=*", "<-*", "=*>", "-*>"};
    for (String p : patterns) {
      Matcher A = Pattern.compile(p).matcher(s);
       while (A.find()) {
        System.out.println(A.group());
      }         
    }

but this doesn't:

      String p = "<=*|<-*|=*>|-*>";
      Matcher A = Pattern.compile(p).matcher(s);
       while (A.find()) {
        System.out.println(A.group());
      }

No idea why. It often reports "<" instead of "<====" or similar.

What is wrong?

© Stack Overflow or respective owner

Related posts about regex

Related posts about java