• 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

Regex Problem

 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
You could try using an HTML parser, and catch all text:
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic