Page 1 of 1

Regex: match a string in span tag

Posted: Tue Oct 07, 2014 10:19 am
by jarid3421
I want to programmatically block a page, if a certain string is present in the title. The below code is JScript .NET, which is basically a .NET version of Javascript.

Code: Select all

var bodyString = oSession.GetResponseBodyAsString();     // oSession is a Fiddler object session
            if (oSession.oResponse.MIMEType.Contains("html")) {
                    var regex = /NotYetComplete/;
                    var text  = /NotYetComplete/
                    if (regex.test(text)) 
                        {
                          oSession.oRequest.FailSession (404, "Blocked", "Fiddler blocked product service request"); // Block the page
                        }
                    }
                }
Basically, How do I tell Regex to find the string episode present in span tag; If found, then block the page?

Code: Select all

<span id="eow-title" class="watch-title  " dir="ltr" title="............episode............">
Example:
<span id="eow-title" class="watch-title " dir="ltr" title="The monster truck show - episode 12">

<span id="eow-title" class="watch-title " dir="ltr" title=" Pt 1 Combat Shotgun Shootout: episode09">

Thank you

Re: Regex: match a string in span tag

Posted: Tue Oct 07, 2014 11:32 am
by Christopher
Use preg_match(). You will need to use ungreedy matches, so broken down you would search for '<span ' then '.*?' then 'title="' then '.*?' then 'episode' then '.*?' then '>'.