Organizational Research By

Surprising Reserch Topic

java equivalent to phps preg replace callback


java equivalent to phps preg replace callback  using -'java,php,regex,preg-replace'

I'm in the process of moving an application from PHP to Java and there is heavy use of regular expressions in the code.  I've run across something in PHP that doesn't seem to have a java equivalent:

preg_replace_callback()


For every match in the regex, it calls a function that is passed the match text as a parameter.  As an example usage:

$articleText = preg_replace_callback("/\[thumb(\d+)\]/",'thumbReplace', $articleText);
# ...
function thumbReplace($matches) {
   global $photos;
   return "<img src=\"thumbs/" . $photos[$matches[1]] . "\">";
}


What would be the ideal way to do this in Java?
    

asked Oct 19, 2015 by maurya
0 votes
4 views



Related Hot Questions

5 Answers

0 votes
NULL
answered Oct 19, 2015 by badhwar.rohit
0 votes
NULL
answered Oct 19, 2015 by tejas lakhani
0 votes
NULL
answered Oct 19, 2015 by tseetha
0 votes
NULL
answered Oct 19, 2015 by atulpariharmca
0 votes
NULL
answered Oct 19, 2015 by pradip.bhoge

...