Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Regular Expression

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
Michal080800
Asked:
Michal080800
1 Solution
 
substandCommented:
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
 
Michal080800Author Commented:
I'd like to use regular expression.
Thanks.
0
 
burcarpatCommented:
(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
 
bkrahmerCommented:
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
 
tinchosCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now