regex

Regex.IsMatch expression

What could be the exact Regex.IsMatch expression for span[class|align|style] I tried with this one but i am not getting exact expected result if (!Regex.IsMatch(n.Value, @"span\[.*?style.*?\]", RegexOptions.IgnoreCase)) n.Value = Regex.Replace(n.Value, @"(span\[.*?)(\])", "$1" + ValToAdd + "$2"); I am checking if the span con...

How to use a variable as modifier in a substitution

Is there a way to use a variable as modifier in a substitution? my $search = 'looking'; my $replace = '"find: $1 ="'; my $modifier = 'ee'; s/$search/$replace/$modifier; I need to use an array of hashes to make bulk search-replace with different modifiers. ...

Regex that looks for a certain number of digits in a string?

When a user submits a form I need to make sure that the input contains at least a minimum number of digits. The problem is that I don't know what format the input will be in. The digits likely won't be in a row, and might be separated by letters, punctuation, spaces, etc. I don't care about the rest of the string. I'd like to check this...

ksh-style left and right string stripping up to matched expression?

How can one strip the left parts and right parts off strings up to a matching expression as in ksh? For instance: ${name##*/} ${name%/*} (see http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html for ksh examples). I can't seem to figure out a simple way of doing this using re module or string module but I must be missing something. ...

Trying to write a regex that matches only numbers,spaces,parentheses,+ and -

I'm trying to write a regular that will check for numbers, spaces, parentheses, + and - this is what I have so far: /\d|\s|\-|\)|\(|\+/g but im getting this error: unmatched ) in regular expression any suggestions will help. Thanks ...

Groovy Regex problem

I have a Groovy script that converts some very poorly formatted data into XML. This part works fine, but it's also happily passing some characters along that aren't legal in XML. So I'm adding some code to strip these out, and this is where the problem is coming from. The code that isn't compiling is this: def illegalChars = ~/[\u0000-...

Mercurial - User Specific Ignore file

I am trying to get mercurial to ignore hidden files for a specific user. I used the directions here: http://stackoverflow.com/questions/2395179/how-to-make-mercurial-ignore-all-hidden-files and got it to ignore files in a specific repo. I want to extend this behavior to all hg repos for a specific user. The hgrc man page says yo...

Regular expression - excluding a character

Here is an example: s="[email protected]" s.match(/+[^@]*/) Result => "+subtext" The thing is, i do not want to include "+" in there. I want the result to be "subtext", with out the + ...

mod_rewrite: redirect top level directories to a file

I'd like to redirect all top level directories to a file using mod_rewrite. So the following should redirect there: - http://example.com/test - http://example.com/test8/ - http://example.com/test_9231/ The following should NOT redirect there: - http://example.com/test.php - http://example.com/test_9231/test/ - http://example.com/t...

PHP recursive variable replacement

Hello there, I'm writing code to recursively replace predefined variables from inside a given string. The variables are prefixed with the character '%'. Input strings that start with '^' are to be evaluated. For instance, assuming an array of variables such as: $vars['a'] = 'This is a string'; $vars['b'] = '123'; $vars['d'] = '%...

Regular Expression fails in IE, but works in Chrome and Firefox?

I have the following asp.net markup: <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" ValidationGroup="passwordValidation"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ControlToValidate="txtPassword" Text="Required" ValidationGroup="passwordValidation" /> <...

Remove part of URL

Hello, i have a url like this http://example.com/blog/photos/photos/gallery/image/1. And i need to remove the second photos folder. How do i remove the part using mod_rewrite and .htaccess? For your interest /blog is my document root. Thanks a lot for any suggestions, Steve EDIT You should know that the URLs being generated by Word...

Parse string to get an array of the URLs

Hi, Imagine I have a string - something like this: This is some really cool text about http://google.com/ and it also contains some urls like http://apple.com/ and its very nice! This is too long and I need to do some magic stuff to fix this very big problem. Oh no. As you can see there are two URLs in the string and somehow, assumin...

Regular Expression Word Boundary and Special Characters

I have a regular expression to escape all special characters in a search string. This works great, however I can't seem to get it to work with word boundaries. For example, with the haystack add + or add (+) and the needle + the regular expression /\+/gi matches the "+". However the regular expression /\b\+/gi doesn't. An...

Why does Flex say this is an "unrecognized rule"?

In the following: space ([ \t\f\r])+ opt_space ([ \t\f\r])* cpp ^{opt_space}#{opt_space} word [A-Za-z_][A-Za-z_0-9]* arg_macro {cpp}define{space}{word} /*arg_macro ^{opt_space}#{opt_space}define{space}{word}*/ %% {arg_macro} ; %% I get an error message test.l...

How to parse a quoted search string using regex?

Given a search string "cars 'cats and dogs' fish 'hammers'", what's the best regex for capturing all search terms. It should support single and double quotes. A Ruby friendly answer if possible. ...

Newbie to regular expression

Hello, I have been reading about regular expressions for around a couple of hours and I still cannot get my head around this: I am trying to pull the anchor text from a link that is formatted this way: <h3><b>File</b> : <a href="/en/browse/file/variable_text">i_want_this</a></h3> I want only the anchor text for the link : "i_want_this...

How can I find a single occurrence of a non-latin character using regular expressions?

I am using a regular expression to see if there is a single non-latin character within a string. $latin_check = '/[\x{0030}-\x{007f}]/u'; //This is looking for only latin characters if(preg_match($latin_check, $_POST['full_name'])) { $error = true; } This should be checking to see if there is at least one character pres...

in perl how to find substring that doesn't match a pattern

hi I need to find the complement of this: $_ = 'aaaaabaaabaaabacaaaa'; while( /([a][a][a][a])/gc){ next if pos()%4 != 0; my $b_pos = (pos()/4)-1; print " aaaa at :$b_pos\n"; } That is, a suite of 4 caracters that is not 'aaaa'. The following doesn't work $_ = 'aaaaabaaabaaabacaaaa'; while( /([^a][^a][^a][^a])/gc){ ...

Problem with regex for text parsing (similar to textile)

I'm banging my head against the wall trying to figure out a (regexp?) based parser rule for the following problem. I'm developing a text markup parser similar to textile (using PHP), but i don't know how to get the inline formatting rules correct -- and i noticed, that the textile parsers i found are not able to format the following text...