-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?

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
JBalaguero
  • 181
  • 2
  • 13

3 Answers3

2

Your regex is absurd. Just use:

xml = xml.replaceAll( "</?ROOMS>", "" );
clcto
  • 9,530
  • 20
  • 42
0

You can probably use this regex :

<[\/]?ROOMS>
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
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,481
  • 1
  • 16
  • 33
  • `/` 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