-1

I need to replace the ROOMS start and end tag from an xml file.

<A><ROOMS><B></B></ROOMS></A> 

becomes

<A><B></B></A>

And also

<A><ROOMS><B></B></ROOMS></A> 

becomes

<A><B></B></A>

I tried

Pattern.compile("\\\\\\\\<(.*)ROOMS\\\\\\\\>").matcher(xml).replaceAll("")

, but it does not work.

Can anybody help me?

JBalaguero
  • 151
  • 1
  • 10

3 Answers3

2

Your regex is absurd. Just use:

xml = xml.replaceAll( "</?ROOMS>", "" );
clcto
  • 9,370
  • 18
  • 40
0

You can probably use this regex :

<[\/]?ROOMS>
Sotirios Delimanolis
  • 263,859
  • 56
  • 671
  • 702
Mayank Agarwal
  • 376
  • 2
  • 9
0

Try using

<[/]?ROOMS>

as your pattern. It uses the ? flag to indicate that the XML-closing forward slash should occur 0 or 1 times.

sumitsu
  • 1,441
  • 16
  • 32
  • `/` has no special meaning in regexes, so you don't need to enclose it in square brackets or escape it with a backslash. – Alan Moore Jun 20 '14 at 16:46