-3

Possible Duplicate:
Regex help required

I am trying to replace two or more occurences of <br/> (like <br/><br/><br/>)tags together with two <br/><br/> with the following pattern

Pattern brTagPattern = Pattern.compile("(<\\s*br\\s*/\\s*>\\s*){2,}",
    Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

But there are some cases where '<br/> <br/>' tags come with a space and they get replaced with 4 <br/> tags which was actually supposed to be replaced with just 2 tags.

What can i do to ignore 2 or 3(few) spaces that come in between the tags ?

Community
  • 1
  • 1
Arun Abraham
  • 4,011
  • 14
  • 54
  • 75
  • 5
    exact duplicate of [Regex help required](http://stackoverflow.com/questions/3872652/regex-help-required) – Sean Bright Oct 06 '10 at 13:48
  • You have an "edit" link right under the question tags that you can use to edit your original question. No need to open a new one. As you've seen, these will get closed soon and earn you downvotes. But you *should* definitely answer the comments on your previous question, also by editing your question. – Tim Pietzcker Oct 06 '10 at 14:11
  • @Tim Pietzcker: Thanks a tim, i am kinda new to this and was in a hurry :) – Arun Abraham Oct 08 '10 at 07:44

1 Answers1

-1

You can do that changing a little your regex:

Pattern brTagPattern = Pattern.compile("<\\s*br\\s*/\\s*>\\s*<\\s*br\\s*/\\s*>\\s*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

This will ignore every spaces between two
. If you just want exactly 2 or three, you can use:

Pattern brTagPattern = Pattern.compile("<\\s*br\\s*/\\s*>(\\s){2,3}<\\s*br\\s*/\\s*>\\s*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
greuze
  • 4,250
  • 5
  • 43
  • 62
  • 2
    Neither of those lines will compile in Java – tim_yates Oct 06 '10 at 13:56
  • 2
    I used the same syntax that the user used in the question, I don't know the language he is using. I just added the thing he needed in the middle, using his syntax (he didn't say it was Java). In Java you should double-escape the characters (but you should change the question in that case) – greuze Oct 06 '10 at 14:12
  • You use the right syntax since the edit, the question was always tagged as Java, and the regular expression in the question is fine, and works as expected. Changing the regex wasn't required http://stackoverflow.com/questions/3872652/regex-help-required – tim_yates Oct 06 '10 at 22:31