0

I would like to make a wiki syntax parser in Java. I have one in PHP that goes a little something like this:

private static function runAllConversions($pString) {
    $tConverted = $pString;
    $tConverted = stripTags($tConverted); 

    // Bold and italic text.
    $tConverted = preg_replace('/\'\'\'\'\'([^\n\']+)\'\'\'\'\'/',
        '<strong><i>${1}</i></strong>', $tConverted);

In replacement I was thinking of replaceAll instead of the preg_replace in PHP. I guess it would be something like:

// Bold text in Java.
converted = converted.replaceAll('/\'\'\'([^\n\']+)\'\'\'/',
    '<strong>${1}</strong>', converted);

Any one got any good suggestions for that? Thanks!

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Tim
  • 531
  • 2
  • 7
  • 25

1 Answers1

2
converted = converted.replaceAll("'{5}([^\n']+)'{5}", "<strong><i>$1</i></strong>");
  • I used '{5} instead of ''''' but they are the same.
  • The two delimiters / in PHP are specific to PHP. They should not appear in Java's regex.

BTW, you may use an existing MediaWiki parser instead.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005