regex

Use Powershell to print out line number of code matching a RegEx

I think we have a bunch of commented out code in our source, and rather than delete it immediately, we've just left it. Now I would like to do some cleanup. So assuming that I have a good enough RegEx to find comments (the RegEx below is simple and I could expand on it based on our coding standards), how do I take the results of the fi...

Java Regular Expression Problem

I have a group of lines like the following: tb-set-node-recipe $vpn1 W2K3_SP2_VPN_SRV tb-set-node-os $vpn2 I_W2K3_SP2_VPN_SRV tb-set-node-os $xpcli1 I_XP_SP3_VPN_CLI tb-set-node-os $xpcli2 I_XP_SP2_VPN_CLI tb-set-node-os $xpcli3 I_XP_SP1_VPN_CLI tb-set-node-recipe $ftp1 FC8_KS_FTP_SRV tb-set-node-os $smb1 XP_...

Perl regex: replace all backslashes with double-backslashes

Within a set of large files, I need to replace all occurrences of "\" with "\\". I'd like to use Perl for this purpose. Right now, I have the following: perl -spi.bak -e '/s/\\/\\\\/gm' inputFile This command was suggested to me, but it results in no change to inputFile (except an updated timestamp). Thinking that the problem might ...

Problem with RegExKitLite and ampersands

Hey all, So I'm trying to rip URLs from an NSString using RegExKitLite and I came across an odd problem. NSLog(@"Array: %@", [message componentsMatchedByRegex:@"^(http://)[-a-zA-Z0-9+&@#/%?=~_()|!:,.;]*"]); NSString *message is just some text with a URL within it. The strange thing is it doesn't work with the ampersand in it. If...

Regular Expression Length

I have an issue where I need to use a RegularExpressionValidator to limit the length of a string to 400 Characters. My expression was .{0,400} My question: Is there a way to limit the length of characters to 400 without taking into consideration blank spaces? I want to be able to accept blank spaces in the string but not count it in t...

Python regular expression for multiple tags

Hi, I would like to know how to retrieve all results from each <p> tag. import re htmlText = '<p data="5" size="4">item1</p><p size="4">item2</p><p size="4">item3</p>' print re.match('<p[^>]*size="[0-9]">(.*?)</p>', htmlText).groups() result: ('item1', ) what I need: ('item1', 'item2', 'item3') ...

Posix/Perl regex in php

I have the simple regular expression: \{[0-9]*\} which works fine with PHP's ereg_ functions (Posix compatible), but I need to use the preg_match_all function, which doesn't have an ereg_ equivalent. My expression above doesn't seem to work with preg_ (perl compatible) functions. How can I go about "converting" it to be perl compatibl...

Need to alter regex to allow for special characters

Hi, I have the following bit of code in my htaccess that will allow a users ID to only be alphanumeric and include underscores and hyphens: RewriteRule ^([A-Za-z0-9_-]+)$ profile.php?ID=$1 [QSA,L] I've recently imported over 1000 usernames from a social networking platform that allowed usernames to contain special characters, but this...

Regular expression to find <% but exclude <%@ ?

Hi. Can someone provide me with a regular expression that will find this string : <% but will exclude this string : <%@ Thanks. ...

Why are regular expressions called "regular" expressions?

Why are regular expressions called regular expressions? ...

Regex: replace backslash with double-backslash, but not double-backslash with quadruple-backslash

I have the following regex: s/\\/\\\\/g This does a nice job of replacing all "\" characters with "\\". However, I want to guard against matching backslashes that are adjacent to other backslashes. If I do this: s/[^\\]\\[^\\]/\\\\/g it only catches non-adjacent backslashes. But now there's the obvious problem that the matches i...

Conditional replacement with regex

Hi all, I'm a relative newb when it comes to regexes, but i'm starting to get the hang of it. I started writing a method in java to "linkify" a string - that is, scan it for any references of urls (i.e, "http://...") or strings that look like web addresses ("www.example.com...") So, for example, if I had a string that looked like this...

Regular Expression sub-expressions

I'm working on a regular expression (in .Net) that needs to mark subexpressions. Sample inputs are: EFBCFEyy EFBQFEyyQ EFBQFE yy Q EFBMFEyyMM EFByyMFEMM What I need is to pull out all of the sub-expressions delineated by "yy" or "MM". The expression I've got so far works for the first few strings, but not the final pair. There may be...

How to use regex to split set-cookie header

How would I use regex to split the set-cookie header into name and value: Eg. test_cookie=Cookie+check; path=/; domain=.Site.com name: test_cooke value: Cookie+check; path=/; domain=Site.com ...

Regular Expressions and negating a whole character group

I'm attempting something which I feel should be fairly obvious to me but it's not. I'm trying to match a string which does NOT contain a specific sequence of characters. I've tried using [^ab], [^(ab)], etc. to match strings containing no 'a's or 'b's, or only 'a's or only 'b's or 'ba' but not match on 'ab'. The examples I gave won't ...

Validating Dates in Javascript with Unusual Form Field Ids - Salesforce.com Web-To-Case Integration

Ok, I need help. This is my first question here. Background: I am working on a charity project, and my portion of the project is to build the Web-To-Case functionality with Salesforce.com. Salesforce.com, if you were unaware, gives its software away free to qualified non-profits. Anyway, the Web-To-Case feature in Salesforce.com ge...

.NET Regex match space character when IgnorePatternWhitespace is on

I have a large regular expression and I've turned on IgnorePatternWhitespace so I can make it more readable. My problem is that I want to match a literal space character. What's the best way to do that? An example: Regex myRegex = new Regex(@" (?> <table[^>]*> ) # Find a table (?> .*?<tr> ) # Find the first row (?> .*?<th> ) # ...

Regular Expression to match a single page or page range?

Hey folks. I'm struggling with a regular expression that will match input in a "single page/page range" text box, meaning the user can enter either a single integer or an integer range in a [lowerBound]-[upperBound] format. For example: 11 : match 2 : match 2-9 : match 2a : not a match 19- : not a match Is this possible wit...

Context-free grammar describing regular expressions?

I'm trying to write a regular expression engine. I'd like to write a recursive descent parser by hand. What would a context-free grammar without left recursion for the language of regular expressions (not the languages that can be described by regular expressions) look like? Would it be easiest to re-factor out the syntactic sugar, i.e. ...

Vim substitution of a list of words with another same length list of words?

I need to substitute a list of words with with an equally long list of words. So for example you have: "a","b","c","d","e","f" And you want to replace each word with the uppercase version of each word: "A","B","C","D","E","F" I know how to find each string using the regex: (a\|b\|c\|d\|e\|f) I know you could do a global substitution ...