• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex Problem  RSS feed

 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I have a string of type:



Precisely a string with many html tags embedded in it.

What i want out of it is, the simple string i.e. "Hello how are you doing today?" to display it on the screen.

I have tried multiple regex expressions and failed to get the output. Will be really glad if anybody could help me on this.

Thanks in advance.
[ August 28, 2008: Message edited by: Anubhav Anand ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which ones have you tried? How have they failed? The key will likely be to use non-greedy (or reluctant) quantifiers.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try using an HTML parser, and catch all text:
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Ulf:

I had been trying various sets of regex expressions in split,replace and also using pattern and matcher classes. But, all the regex i used were stripping off the entire content between the first opening < and last closing >
e.g. i tried the regex : string.replace("<.*>","")

To Rob:
Thanks for the suggestion, seemed pretty cool, but I just came up with a solution. Thanks a lot for your time.

The solution that worked for me is:


[ August 28, 2008: Message edited by: Anubhav Anand ]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had been trying various sets of regex expressions in split,replace and also using pattern and matcher classes. But, all the regex i used were stripping off the entire content between the first opening < and last closing >
e.g. i tried the regex : string.replace("<.*>","")


As Ulf suggested, perhaps you need to use a reluctant qualifier. e.g. String.replaceAll("<.*?>", "")

Henry
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, for pin pointing that.
Amidst so many issues I just couldn't think much.

Thanks to all for the help..
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!