regex

Groovy: Escaping an arbitrary (unknown) regular expression

I want to split a string via String.split(k) where k is an arbitrary string (read from intput). The problem is that k can be any string and thus may include regular expression operators, such as: "*[". In such cases the split method fires an exception since the regular expression is not well formed. What I am looking for is a way to ...

javascript regular expression

How can I replace/append something (22) string to something, using some kind of expression matching something is not a constant its always different but the part (integer) is always the same. cheers EDIT I see that this something is a bit confusing(for me as well). Here is what I mean. I have a string - a word . Which contains alpha e...

(grep) Regex to match non-ascii characters?

On linux i have a directory with lots of files. Some of them have nonASCII characters, but they are all valid UTF8. One programme has a bug that prevents it working with nonASCII filenames, I have to find out how many are affected. I was going to do this with find and then do a grep to print the nonASCII characters, and then do a wc -l t...

Java Regular Expression

Hi, I need to define a (Java) regex that will match any string that does NOT contain any of these 'foo' or 'foos' as a whole word 'bar' or 'bars' as a whole word 'baz' or 'bazs' as a whole word Is it possible to express this as a single regex? I know it would be more readable to use 3 separate regexs, but I'd like to do it in one if...

regex for interval of years

In C#, I want to write a regular expression that will accept only years between 1900 and 2099. I tried ^([1][9]\d\d|[2][0]\d\d)$, but this does not work. Any ideas? So i have in a class: [NotNullValidator(MessageTemplate = "Anul nu poate sa lipseasca!")] // [RangeValidator(1900, RangeBoundaryType.Inclusive, 2100, RangeBoundar...

ASP.Net RegularExpression Validator - Parsing bug

I wanted to write a regular expression using the ASP.Net RegExp validator that would ensure a field contains only numeric and decimal values, and at least one character. ^[0-9]{1,40}(\.[0-9]{1,2})?$ Essentially: [0-9]{1,40} - meaning at least one to 40 numeric characters. The ASP.Net regexp validator does not fire for an empty field ...

Visual Studio Find and Replace Regular Expressions help

Hi, I'd like to replace some assignment statements like: int someNum = txtSomeNum.Text; int anotherNum = txtAnotherNum.Text; with int someNum = Int32.Parse(txtSomeNum.Text); int anotherNum = Int32.Parse(txtAnotherNum.Text); Is there a good way to do this with Visual Studio's Find and Replace, using Regular Expressions? I'm not s...

Regex that expresses "at least one non-digit"

I want to validate usernames according to this schema: Allowable characters: letters, numbers, hyphen, underscore First character must be a letter or a number The username cannot be all numbers This regular expression satisfies 1 and 2 above, but I can't figure out how to satisfy 3: /^[a-zA-Z\d][\w\-]+$/ (I'm using Ruby, if that's...

RewriteRule RegEx - Add another variation of subdirectory level mapping to URL

I am passing one of the following URLs to a site an want it to split into the proper parameters. http://example.com/storevar?search_term http://example.com/storevar/?search_term http://example.com/storevar http://example.com/storevar/ http://example.com/storevar/search_term http://example.com/storevar/search_term/ ...

Regex lookahead ordering

I'm pretty decent with regular expressions, and now I'm trying once again to understand lookahead and lookbehind assertions. They mostly make sense, but I'm not quite sure how the order affects the result. I've been looking at this site which places lookbehinds before the expression, and lookaheads after the expression. My question is, d...

what does this line do in Perl? ($rowcol =~ m/([A-Z]?)([0-9]+)/);

What does this line do in Perl? my @parsedarray = ($rowcol =~ m/([A-Z]?)([0-9]+)/); $rowcol is something like A1, D8 etc... and I know that the script somehow splits them up because the next two lines are these: my $row = $parsedarray[0]; my $col = $parsedarray[1]; I just can't see what this line does ($rowcol =~ m/([A-Z]?)([0-9]+...

php/regex: How to replace part of a found pattern, but leaving the rest as it is?

Hi! How can I replace a substring in a found pattern, but leaving the rest as it is? (EDIT: The real case is of course more complicated than the example below, I have to match occurances within xml tags. That's why I have to use regex!) Let's say I want to change occurances of the letter "X" within a word to the letter "Z". I want ...

tricky string matching

I want to find the first index of substrings in a larger string. I only want it to match whole words and I'd like it to be case-insensitive, except that I want it to treat CamelCase as separate words. The code below does the trick, but it's slow. I'd like to speed it up. Any suggestions? I was trying some regex stuff, but couldn't f...

Use regex to extract integer from url in a string with php

I have a url such as the example below http://www.website.com/page.php?pid=263547322425&foo=too How can i use regex to get the value of pid. Thats to say the value from the end of pid= until the &? ...

negative lookbefore for a blackslash in ruby 1.9

I want to match every '[' or ']' that's not preceded by a backslash in ruby 1.9 I tried: /?<!\134[\[\]]/ and /?<!\\\\[\[\]]/ but I get a 'target of repeat operator not specified' ...

VBScript regex question (.*)

Hi, I am using VBscript in QTP and I am a bit confused: Browser("name:=.*") //works Why Browser("name:=*") does not work? Why is there a . character? Thank you! ...

More string matching features

Is it possible to create a regex that matches all strings with five a's and five b's? Like aaaaabbbbb or ababababab or aabbaabbab. I imagine it would require polynomial time for a deterministic engine. Are there other matching languages which would enable such matching? Update: I wanted to use the kind of expression for searching, s...

n-grams using regex

I am working on an augmentative and alternative communication (AAC) program. My current goal is to store a history of input/spoken text and search for common phrase fragments or word n-grams. I am currently using an implementation based on the lzw compression algorithm as discussed at CodeProject - N-gram and Fast Pattern Extraction Algo...

Regular expression to exclude chars for a valid URL

hi, I'd like to create a filter which allows almost all chars but without / < > ? = I've read in some site, I shoud use the ^ char inside ranges, but if I try it doesn't work properly: mod_rewrite: RewriteRule ^(user/)([^\<\>\?=]+)([/]?)$ user.php?username=$2 php for validation: return eregi ("[^\<\>\?=/]", $value); how I shou...

Any preg_match to check if a url is a youtube/vimeo/dailymotion video link ?

What's the best preg_match syntax to check if a url is a video link of youtube/vimeo/ or dailymotion? maybe if it's hard, then just to check the domain name. Thanks ...