How to parse overlapping string?....@@.

M

mike

regards:
I have the following string:
<a>XXXX<b></a>YYYYY</b>

How to write java codes to parse "<a>XXXX<b></a>YYYYY</b>"
and then output"<a>XXXX</a><b>YYYYY</b>"
any idea is welcome

Thank you
May goodness be with you all
 
K

koos

mike said:
regards:
I have the following string:
<a>XXXX<b></a>YYYYY</b>

How to write java codes to parse "<a>XXXX<b></a>YYYYY</b>"
and then output"<a>XXXX</a><b>YYYYY</b>"
any idea is welcome
just scan the string for start-tags and put them
on a stack. When an end-tag occurs, whatever it is,
pop the last start-tag from the stack and create
a new end-tag...


koos.
 
A

Antti S. Brax

just scan the string for start-tags and put them
on a stack. When an end-tag occurs, whatever it is,
pop the last start-tag from the stack and create
a new end-tag...

Wouldn't you end up with "<a>XXXX<b></b></a>YYYYY</b></b>"
then?
 
A

Ann

mike said:
regards:
I have the following string:
<a>XXXX<b></a>YYYYY</b>

How to write java codes to parse "<a>XXXX<b></a>YYYYY</b>"
and then output"<a>XXXX</a><b>YYYYY</b>"
any idea is welcome
Would tidy work?
 
A

Ann

I just tried tidy:
line 1 column 9 - Warning: missing </b> before </a>
line 1 column 9 - Warning: trimming empty <b>
line 1 column 20 - Warning: discarding unexpected </b>
3 warnings, 0 errors were found!

The result was
<a>XXXX</a>YYYYY
 
D

digidigo

How about

input = input.replaceAll("<b></a>","</a><b>")
Also this would be simple to do with regular expressions.

Dave
 
M

mikeotp

regards:

How to do it with regular expressions?...@@

Any suggestion is welcome.
thank you
May goodness be with you all
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top