regex

In Python, how do I split a string and keep the separators?

Here's the simplest way to explain this. Here's what I'm using: re.split('\W', 'foo/bar spam\neggs') -> ['foo', 'bar', 'spam', 'eggs'] Here's what I want: someMethod('\W', 'foo/bar spam\neggs') -> ['foo', '/', 'bar', ' ', 'spam', '\n', 'eggs'] The reason is that I want to split a string into tokens, manipulate it, then put it back ...

Javascript replacing new line character

This is driving me crazy, I have a string in the format: <br /> twice<br /> imap Test wrote:<div class="nestedMessage1"><br /> > nested<br /> ><br /> > [email protected] wrote:<div class="nestedMessage2"><br /> >> test<br /> >><br /> >> -- <br /> >> Message sent via AHEM.<br /> >> </div><br /> ><br /><br /></div> And the following cod...

urlrewriter.net

Hello all! I have a question concerning urlrewiter. I want to rewrite the following url like this: <rewrite url="~/sportswear/browse-by-category/(\d+)/(.+)/(\d+)" to="~/Browse.aspx?cid=9&amp;type=category&amp;mid=$1&amp;p=$2" /> This does work but my get variable p cannot be read. However when i write 'shoes' which is the categorynam...

How can I use a regular expression to validate month input?

Greetings, I am setting up this example Perl snippet to validate for months in a date: Some scenarios I want to accept are: MM M #!/usr/bin/perl use strict; use warnings; my $pattern; my $month = "(0[1-9]|1[012])"; my $day = "(0[1-9]|[12]\d|3[01])"; system("cls"); do { print "Enter in a month: "; chomp($pattern = <STDIN>)...

Email check regular expression with bash script

Hello, im trying to make a bash script to check if a email address is correct. I have this regular expression: [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])? Source: http://www.regular-expressions.info/email.html And this is my bash script: rege...

Regex help: Match any image file beginning with an underscore

The statement below will load all images that do not begin with an underscore character... if (!is_dir($file) && preg_match("/^[^_].*\.(bmp|jpeg|gif|png|jpg)$/i", $file)) I need to modify it so that it only loads images that DO BEGIN with an underscore. ...

Regex Matching numbers with floating point

I have this pattern: [0-9]*\.?[0-9] It matches numbers but it also matches 3.5.4 as: 3.5 .4 How to fix that(this input shouldn't be matched)? UPDATE: this also should work on input: 1 3.5.4 10 1.2. is not allowed .3 is allowed any char that is not poart of numer is not allowed, like: a1 2.4f 3. 45, 67! ...

C# reliable way to pattern match?

At the moment I am trying to match patterns such as text text date1 date2 So I have regular expressions that do just that. However, the issue is for example if users input data with say more than 1 whitespace or if they put some of the text in a new line etc the pattern does not get picked up because it doesn't exactly match the patter...

Reformatting code with Regular Expressions

We have an ArrayList of items in several classes which are giving me trouble every time I'd like to insert a new item into the list. It was a mistake on my part to have designed the classes in the way I did but changing the design now would be more headache than it's worth (bureaucratic waterfall model.) I should have anticipated forma...

Regular Expression Period Issue

((https?|ftp)\:\/\/|www.)(\S+[^.*]) I would like this expression to check for . in succession to each other. If it finds two or more periods back to back, the expression should fail. On the other hand, if it succeeds, I want it to match every character and/or symbol up until the first white space encountered. In other words: www.yahoo....

Javascript Regex literal with /g used multiple times

Hello, I have a weird issue working with the Javascript Regexp.exec function. When calling multiple time the function on new (I guess ...) regexp objects, it works one time every two. I don't get why at all! Here is a little loop example but it does the same thing when used one time in a function and called multiple times. for (var i ...

How can I rewrite URLs except those of a particular domain?

Hi. Can you please help me to make perl regexp to replace (http://.+) to http://www.my1.com/redir?$1 but do nothing for urls like http://www.my1.com/ or http://my1.com/ For instance I need to replace http://whole.url.site.com/foo.htm to http://www.my1.com/redir?http://whole.url.site.com/foo.htm http://www.google.com to http://www.my1.co...

Any preg_match() to extract image urls from text ?

Hi, i need a preg_match() syntax or something similar to extract JPG or PNG or GIF URLs from a mixed text and put them in an array or at last store the first url. maybe some syntax which searchs for strings that are beginning with http and ending with jpg/png/gif.. i believe it can be done with preg_match() Note: the text can be like ...

How to write a regular expression to match a string literal where the escape is a doubling of the quote character?

I am writing a parser using ply that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e. 'I don''t understand what you mean' is a valid escaped FORTRAN string. Ply takes input in regular expression. My attempt so far does not work and I don't unders...

Regex - Match alpha characters that don't match a subset of alpha characters (C#)

Say I have a collection of strings "123AB", "456CDEF", "789G", "012-HI". How do I find all the strings that are number(1 or more) followed by alpha(1 or more) with no special characters, where the alpha characters are not AB? To clarify, the regex applied to the previous collection should yield "456CDEF" and "789G". "123AB" is ignor...

simple PHP preg_replace question

Here's a simple preg_replace $string = 'src="index.php'; $string = preg_replace("/(src=('|\")+[^(http:|https:)])/i", "src=\"http://domain.com/", $string); echo $string; I expect the result to be src="http://domain.com/index.php but it turns out to be src="http://domain.com/ndex.php. I must be missing something here.. ...

Match dynamic string using regex

I'm trying to detect an occurrence of a string within string. But the code below always returns "null". Obviously something went wrong, but since I'm a newbie, I can't spot it. I'm expecting that the code returns "true" instead of "null" var searchStr = 'width'; var strRegExPattern = '/'+searchStr+'\b/'; "32:width: 900px;".match(new R...

How to get the previous word with regex?

Hello, I have a path like this one: C:\Development.TFS\Examn\R4-branch\Web\OrganisationManager\themes\blue\css And I need a regex to get the word "blue" out of there. I tried, but didn't find a solution yet. It's practically getting the word before the last word from that string. Please help, thank you ...

Combining these two Regular Expressions into one

I have the following in C#: public static bool IsAlphaAndNumeric(string s) { return Regex.IsMatch(s, @"[a-zA-Z]+") && Regex.IsMatch(s, @"\d+"); } I want to check if parameter s contains at least one alphabetical character and one digit and I wrote the above method to do so. But is there a way I can combine the two regula...

Regex: Match this string

I can't figure this out: 22.584\r\n\t\t\tl-6.579-22 I want to match the "\r\n\t\t\t" and replace with a single space " ". Problem is the number of "\t", "\r", and "\n" fluctuates, as do the surrounding characters. Help! ...