Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java equivalent of PHP preg_replace?

843835Apr 18 2003 — edited Apr 19 2003
Hi,

I'm have some regex PHP functions that I would like to translate to Java. My problem seems to be that the Matcher object in Java doesn't seem to be able to recognize backreferences in the Pattern object.

A simple example:
blah blah blah ---> <b>blah blah blah</b>
(stupid forum parser, the first part should have the 'b' in square brackets, not pointed brackets)

The PHP code used to do this is:
$string = preg_replace("/\[b\](.*?)\[\/b\]/si", "<b>\\1</b>", $string); 
I can't seem to duplicate this behaviour in Java.

Any help would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2003
Added on Apr 18 2003
3 comments
935 views