How to use regular expressions

602 views
Skip to first unread message

Code monkey

unread,
Apr 27, 2012, 7:42:06 PM4/27/12
to httpf...@googlegroups.com
Hello all,

thanks for helping me out last time. this time i had some trouble finding how to use regex. I am new to regex. This is what i want to do:


    if (oSession.HostnameIs(HOSTSITE) && oSession.uriContains(REGULAREXPRESSION)) {
                oSession
["ui-color"] = "red";
                oSession
["ui-backcolor"] = "yellow";
                count
++;
               
URLlog(oSession);

and i believe the regular expression for this site is http://(?:www\.)?HOSTSITE\.com/(?:embed-)?([\w]{12})+

is this possible? also how would i use REGEX in fiddler. i tried a the example from the website listed:
.*\.txt$

and it told me compile error.

any suggestions?

EricLaw

unread,
Apr 28, 2012, 12:48:51 PM4/28/12
to httpf...@googlegroups.com
I'm not sure what example you are talking about. Your first problem is that uriContains takes a plaintext string, not a regular expression.
 

survivor

unread,
Nov 20, 2012, 10:45:22 AM11/20/12
to httpf...@googlegroups.com
How do you specify options to a regular expression that is specified via a string? Specifically how do you turn on multiline in a utilReplaceRegexInResponse call?
 
Rosendo

EricLaw

unread,
Nov 20, 2012, 1:23:13 PM11/20/12
to httpf...@googlegroups.com
In .NET, you can express regex flags inline before the expression.
 
See the Inline Character option here: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx
 
So, you can use, e.g. (?im)text$ to search for lines that end with "text" (case insensitively).
 
-Eric

survivor

unread,
Dec 7, 2012, 10:48:02 PM12/7/12
to httpf...@googlegroups.com
Hi Eric,
 
It seems that the single line mode (s) regular expression option is on by default and the multiline mode (m) option does not work. For example in this piece of body content:
 
...
var _gaq = _gaq || [];
...
})();
...
 
I would like to replace everything from var to (); with my own content. And it works with this:
 
oSession.utilReplaceRegexInResponse('var _gaq = .*?}\\)\\(\\);', '(new-content)');
 
However in some cases the ending pattern could appear twice so I would like to help it match by indicating that it occurs at the start of a line:
 
oSession.utilReplaceRegexInResponse('(?m)var _gaq = .*?^}\\)\\(\\);', '(new-content)');
 
but it doesn't work (nothing is replaced).
 
 

EricLaw

unread,
Dec 10, 2012, 1:07:30 PM12/10/12
to httpf...@googlegroups.com
Yes, the Single-Line option is on-by-default. It's interesting, but not altogether surprising to learn that the "m" option doesn't override the "s" option.
 
Having said that, this should be simple enough to workaround, given the definition of Single-Line mode:
 

Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n).

You should be able to use [\r?\n] to match an end-of-line sequence.

Reply all
Reply to author
Forward
0 new messages