This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Content Removal with multiline regexp

Hi,

I want to use the content removal in the http-proxy to block out whole advertisement blocks. So here's an example of what one of these would look like:
 [ QUOTE ]
 

    Advertising
  




    
 

[/ QUOTE ] 

now my regexp looks like this:

 [ QUOTE ]
 <> 

[/ QUOTE ] 

this obviously doesn't work, since I need to tell it that newlines may occur too.
So, how would I do that? 

TIA Tom


This thread was automatically locked due to age.
Parents
  • newlines are very ideosyncratic with regexp parsers; depends upon which parser your are using (there are a few: egrep, sed, Perl, Tcl...). Pull down the (e)grep utility (if you don't already have it) and experiment interactively. Enter a case example of the HTML text with line breaks into a file.

    Some regexp engines have a whitespace character (\w) that includes newlines. Astaro knows what was used, so I will defer to their advisory here...

    Teach a man to fish: For starters, try:

         <><>Mastering Regular Expressions.

    It's easier parsing such tags when you can edit them beforehand to throw out weirdo cases (using something like sed) or use another regexp on the results of a regexp (to accommodate a refined Search). What if we get the tag {spaces}DIV??? The expression above would need to be enhanced for that (or not if we knew the browsers our site uses don't accept such an HTML format). Sometimes when you're done, you have something only somebody from the NSA coud make out! And susceptible to false positives too (but I prefer that to a gaping hole!!). For example, what happens if we match with a closing DIV tag not meant for that opening DIV tag? And the "Advert" may not have been between either of the DIVs!

    The regexp window Astaro provides is a great start though. [If you need really precise HTML parsing, Xerces SAX is a good one...]

    It would be great if Astaro tweaked the parsing engine just for the Content Removal to ignore embedded newlines on matches. I can't think of a case where you need to be on the lookout for that when parsing HTML. Then your simple expression above would work...

Reply
  • newlines are very ideosyncratic with regexp parsers; depends upon which parser your are using (there are a few: egrep, sed, Perl, Tcl...). Pull down the (e)grep utility (if you don't already have it) and experiment interactively. Enter a case example of the HTML text with line breaks into a file.

    Some regexp engines have a whitespace character (\w) that includes newlines. Astaro knows what was used, so I will defer to their advisory here...

    Teach a man to fish: For starters, try:

         <><>Mastering Regular Expressions.

    It's easier parsing such tags when you can edit them beforehand to throw out weirdo cases (using something like sed) or use another regexp on the results of a regexp (to accommodate a refined Search). What if we get the tag {spaces}DIV??? The expression above would need to be enhanced for that (or not if we knew the browsers our site uses don't accept such an HTML format). Sometimes when you're done, you have something only somebody from the NSA coud make out! And susceptible to false positives too (but I prefer that to a gaping hole!!). For example, what happens if we match with a closing DIV tag not meant for that opening DIV tag? And the "Advert" may not have been between either of the DIVs!

    The regexp window Astaro provides is a great start though. [If you need really precise HTML parsing, Xerces SAX is a good one...]

    It would be great if Astaro tweaked the parsing engine just for the Content Removal to ignore embedded newlines on matches. I can't think of a case where you need to be on the lookout for that when parsing HTML. Then your simple expression above would work...

Children
No Data