Regex: match a string in span tag

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Forum Newbie
Posts: 7
Joined: Wed Jul 30, 2014 4:06 pm

Regex: match a string in span tag

Post 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............">
<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
User avatar
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Regex: match a string in span tag

Post 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 '>'.
Post Reply