Jump to content

Using Matcher class like preg_match_all in PHP

- - - - -

  • Please log in to reply
1 reply to this topic

#1
rsnider19

rsnider19

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
So in php I can make a regex and pass it to preg_match_all and it gives me a 2D array of all the matches. can you accomplish this in java? The specs of preg_match_all are here:

PHP: preg_match_all - Manual

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Pattern pattern = Pattern.compile("regex here");

Matcher matcher = pattern.matcher("input string here");


while (matcher.find()) {

  System.out.println(matcher.group());

}

If you want an array, you'll have to get it in an array instead of printing it now, in this code sample.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users