• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help - To replace <br> with "" empty string

 
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I have an html string which contains br with beginning and ending <> brackets which I want to replace with the "" empty string. I am using the String.replaceAll() method eg message.replaceAll("[<(.|)+?>]", " "). I am able to delete the < and > but not the substring "br". Please help me to modify the regex/pattern.

I appreciate your time.

Thank you so much,
Naveen Katoch
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any reason you don't do string.replaceAll("<br>", "");? I am not at a Java compiler so can't tell, but a quick regex test seemed to show it would work...
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,

Thanks for your time. My string is like this
String message = "<strong>" + title + "</strong>" +
"\n" +
"" + message.replaceAll("[<(.|)+?>]", " ") + "";
or message = title + "\n" + message.replaceAll("[<(.|)+?>]", " ");
_messages.add(message);

It is returnning the message with br as it has a substring like
. The returned message after replaceAll is Declined from Product Dispensing by Naveen Katoch br Edit Data Entry br. So I don't want the br in the returned message. Or is it possible to put br and replace with empty string. I am doing the same thing eg final String br = "br"; message = message.replaceAll(br, ""); but I wanted to create a pattern/regex inside replaceAll to replace
with an empty string.

Thanks again for your time,

Naveen Katoch
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not use message.replace("<br>", "")?
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,

Thanks for your time. I fixed it by doing like this message.replaceAll("[<(.|)+?>](
)", " ").

Naveen
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you not answered the question about using the straight-forward approach?
reply
    Bookmark Topic Watch Topic
  • New Topic