html - Combining two regular expressions in java -


i have text this:

[image]bdaypic.jpg[caption]my pic[/caption][/image] 

i should output as:

<figure><img src='bdaypic.jpg'/><figcaption>my pic</figcaption></figure> 

i'm using below code:

string = string.replaceall("\\[image\\](.*?)\\[\\/image\\]", "<figure><img src='$1'/></figure>"); string = string.replaceall("\\[caption\\](.*?)\\[\\/caption\\]", "<figcaption>$1</figcaption>"); 

but i'm getting output

<figure><img src='bdaypic/><figcaption>my pic</figcaption>'</figure> 

[caption][/caption] optional.if there should replaced tag.

the problem seems lie within first replace. capturing between [image] tag , replacing quoted version of content. merged 2 expressions , got after:

        string string = "[image]bdaypic.jpg[caption]my pic[/caption][/image]";         string=string.replaceall("\\[image\\](.*?)\\[caption\\](.*?)\\[\\/caption\\]\\[\\/image\\]","<figure><img src='$1'/><figcaption>$2</figcaption></figure>");         system.out.println(string); 

yields:

<figure><img src='bdaypic.jpg'/><figcaption>my pic</figcaption></figure> 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -