?
Solved

Regular Expression

Posted on 2003-03-27
5
Medium Priority
?
238 Views
Last Modified: 2010-04-01
Hi,

I have a String with html code. I would like to remove some of the html tags from it.

I've downloaded and installed the Regex++, but i cannot seem to find the correct way to implement what i need.

As far as i understand, there is no Remove, or Replace method that i can use.
I'm trying to use the Merge method ...

the regular expression that describes the tag i want to remove is:
char* pattern = "(<\\s*(span)\\s[^>]+>[^<>]*(</(span)>)?)";
boost::RegEx expr(pattern, TRUE);

then i try:
std::string result = expr.Merge(html, "");

but the format string is probably the problem.

Thanks,

Michal.
0
Comment
Question by:Michal080800
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:substand
ID: 8216750
why not do a search for "<span" in the string and if found, find the next ">"

the find functions will return the indexes in the string of where those are at, and then you just replace all indexes between the 2 you get with "", or null.

0
 

Author Comment

by:Michal080800
ID: 8216761
I'd like to use regular expression.
Thanks.
0
 
LVL 7

Accepted Solution

by:
burcarpat earned 500 total points
ID: 8218139
(1) are you using the latest regex package that comes with the boost distribution? (1.30.0)  they changed stuff in the later versions.  if not, you should upgrade.

(2) can you give me a sample content for your "html" variable so that i can test?

(3) also, note that, in general, it's a bad idea to try to parse html code with regex.  it can get pretty complex if you can have all sorts of html constructs

-b
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8223157
I agree with burcarpat.  A more correct way is to use an HTML parser, read the html in, discard the unwanted tags, and print out the result.

brian
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9551266
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Delete/No Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question