regex

Ruby's String#gsub, unicode, and non-word characters

As part of a larger series of operations, I'm trying to take tokenized chunks of a larger string and get rid of punctuation, non-word gobbledygook, etc. My initial attempt used String#gsub and the \W regexp character class, like so: my_str = "Hello," processed = my_str.gsub(/\W/,'') puts processed # => Hello Super, super, super simple...

Regular expression for bounce email message

I am looking for a regular expression (or other method if there is such a thing) for detecting bounce email messages. So far I have been going through our unattended mail box and adding strings that I find into a regex. I figured someone would have something that is already complete rather than me re-inventing the wheel. Here is an exam...

JavaScript DOM XSS Injection validation

Is this regular expression enough to catch all cross site scripting attempts when embedding HTML into the DOM. eg: Such as with document.write() (javascript:|<\s*script.*?\s*>) It is referenced in this document from modsecurity.com http://www.modsecurity.org/documentation/Ajax%5FFingerprinting%5Fand%5FFiltering%5Fwith%5FModSecurity%5...

How to explode date from a string using php preg_match and regex

I am processing strings with a date somewhere in it. There are different ways the date can appear in this string: "… 01.11.2009 18:00-21:00 …" or "… 01.11.2009 18:00-02.11.2009 15:00 …" or "… 01.11.2009 18:00 …" Regardless how the date appears I only need the beginning date "01.11.2009 18:00". So if there are two matches it's just...

Ruby regex for a split every four characters not working

I'm trying to split a sizeable string every four characters. This is how I'm trying to do it: big_string.split(/..../) This is yielding a nil array. As far as I can see, this should be working. It even does when I plug it into an online ruby regex test. ...

This regex matches and shouldn't. Why is it?

This regex: ^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([a-zA-Z0-9\?\=\...

Regular Expression questions

I am learning regular expressions and having a hard time. Can anyone tell me if I'm on the right path with these two problems? -List the words in the language specified by the regular expression (a|b)(c|elipson) -- I am thinking the answer is ac, bc, a,b. Am I right? -Give a regular expression recognizing all words with an odd number o...

Reg Expression in C#

Hi All, <add key="Key1" value="Provider=SQLOLEDB.1;data source=serveripaddress;Initial Catalog=DB1;user id=uid;Password=***"/> I gave the above string,I want to get the serveripaddress,DB1,uid and **** these values from that string. ...

PHP Regexp: Subpattern that might occur more than once

Hey there, I'm trying to write a regular expression for a code like this: <tr> <td>I'm some text</td> <td>1234</td> <td>1231</td> </tr> <tr> <td>I'm some text</td> <td>1234</td> <td>1231</td> <td>7181</td> </tr> (I know, bad html code... ) Now I want an expression that looks for every table row and can han...

Validation to allow space for phone numbers

i have a validation in my .net textbox where it will take only numbers but when i put the the phone format like 080 234234 it will not accept because of a space how to resolve this ? could anyone help in regular expression ? Current expression is this [0-9]+ ...

Validation to allow single space for phone numbers

i have a validation in my .net textbox where it will take only numbers but when i put the the phone format like 080 234234 it will not accept because of a space how to resolve this ? could anyone help in regular expression ? Current expression is this [0-9]+ i want only single space ... no two spaces should be encoraged ...

Drupal views - how to remove string pattern using "Rewrite the output of this field"?

Views - Fields: I want to remove a certain matching word from a returned string by using the "Rewrite the output of this field". Is there extended syntax for this or is there a way to use php string-functions/regex in this field? ...

Finding *two* html tags with Regular Expressions

Hello, I need to pull out the content out of two paragraph tags and break it with a <br /> tag. The input is like so <p> Yay </p> <p> StackOverFlow </p> It needs to be like <p> Yay <br /> StackOverflow </p> What I have so far is <p><?php preg_match('/<p>(.*)<\/p>/', $content, $match); echo($match[1])."..."; ?></p> Which pulls the ...

Regex - Match only letters, numbers, and one space between each word

How can I create a regex expression which will match only letters and numbers, and one space between each word? Good Examples: Amazing Hello Beautiful World I am 13 years old Bad Examples: Hello world I am 13 years old. I am Chuck Norris ...

Simple Regex help for C#

I have an unfinished binary file that has some info that I can recover using regex. The contents are: G $12.Angry.Men.1957.720p.HDTV.x264-HDLH Lhttp://site.com/forum/f89/12-angry-men-1957-720p-hdtv-x264-hdl-538403/ L I Š M ,ABBA.The.Movie.1977.720p.BluRay.DTS.x264-iONN Phttp://site.com/forum/f89/abba-movie-1977-...

What regex must I use?

Hi, I'm writing an application in PHP, and I need to replace any word between <!-- * and * --> with it's correspondenting element in $vars. For example, <!-- *foobar* --> In this case 'foobar' must be replaced by the variable $vars["foobar"]'s value. This is what I have now, but it does not work (it always returns <> :( ): preg_repl...

c regular expression howto

It's been 10 years since I looked at c. I need to write a little program in c that parses a string. I wanted to use regular expressions since I've been using them for years, but I have no idea how to do that in c. I've spent the morning Googling and I can't find any straight forward examples (ie. use this library, this is the methodol...

How can I replace parenthesis in vim

In Vim I have: simulación (fig.),pretexto (fig.),excusa (fig.). My goal is: simulación ,pretexto ,excusa . I have tried with: :%s/\(fig\.\)//g, but it doesn't work. Thanks in advance! Ps: sorry my english ...

How to parse this?

I need to parse out the string that has following structure x:{a,b,c,}, y:{d,e,f} etc. where all entries are numbers so it would look something like this 411:{1,2,3},241:{4,1,2} etc. Forgot to mention: number of comma delimited entries in between {} has no upper limit but has to have at least one entry. I need to get the unique l...

Regular expression for numbers and operator

How to write a regular expression that match " 0-9()+-*/. " ...