regex

What regular expression would strip out all attributes from a BR tag?

What C# regular expression would replace all of these: <BR style=color:#93c47d> <BR style=color:#fefefe> <BR style="color:#93c47d"> <BR style="color:#93c47d ..."> <BR> <BR/> <br style=color:#93c47d> <br style=color:#fefefe> <br style="color:#93c47d"> <br style="color:#93c47d ..."> <br> <br/> with: <br/> basically "remove all attrib...

Can i exclude a word in my pattern?

I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like ab(^hi)+def which will exclude the word hi causeing ab_blah_hi_blah_def to fail? but not ab_blah_h_i_blah_def ...

regex to escape non-html tags' angle brackets

Hi I have an html based text (with html tags), I want to find words that occur within angle brackets and replace the brackets with < and > or even when angle brackets are used as math symobls e.g: String text= "Hello, <b> Whatever <br /> <table> <tr> <td width="300px"> 1 < 2 This is a <test> </td> </tr> </table>"; I w...

Regular expression for getting any letter, symbol, number from 1 to 100 maxlength.

As you can read in the tittle i need a regular expression for getting any letter, symbol, number from 1 to 100 maxlength (any text posible). Can someone provide that for me and maybe a good link to understand how it works. Thank you. ...

JavaScript String Replace with a tricky regular expression

Hi. I'm trying to work out what regular expression I would need to change this string html = '<img style="width: 311px; height: 376px;" alt="test" src="/img/1268749322.jpg" />'; to this html = '<img width="311" height="376" alt="test" src="/img/1268749322.jpg" />'; with the help of Javascript.replace. This is my start: html = ht...

ssh-rsa public key validation using a regular expression.

What regular expression can I use (if any) to validate that a given string is a legal ssh rsa public key? I only need to validate the actual key - I don't care about the key type the precedes it or the username comment after it. Ideally, someone will also provide the python code to run the regex validation. Thanks. ...

Django URL regex question

Hey all! I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way: url(r'^env/(?P<env>\w+)/artifact/(?P<artifact>\w+)/$', 'config.views.ipview', name="bothlist"), Now, this works fine, but what I would like ...

RowFilter.regexFilter multiple columns

I am currently using the following to filter my JTable RowFilter.regexFilter( Pattern.compile(textField.getText(), Pattern.CASE_INSENSITIVE).toString(), columns ); How do I format my textField or filter so if I want to filter multiple columns I can do that. Right now I can filter multiple columns but my filter ...

Validating javascript decimal numbers

I'm using the following regexp to validate numbers in my javascript file: var valid = (val.match(/^\d+$/)); It works fine for whole numbers like 100, 200, etc, however for things like 1.44, 4.11, etc, it returns false. How can I change it so numbers with a decimal are also accepted? ...

Formatting the date in unix to include suffix on day (st, nd, rd and th)

How can I add the suffix on the day number of a unix date? I'll explain. I have a TextMate bundle snippit that writes out today's date. It uses unix date and formatting. Here is the code: `date +%A` `date +%d` `date +%B` `date +%Y` It outputs: Monday 22 March 2010 I would like to add the suffix to the day (st, nd, rd and th) like s...

stripping a query string with php (preg_replace)

http://www.chuckecheese.com/rotator.php?cheese=4&amp;id=1 I want to take out the id, leaving the cheese to stand alone. I tried: $qs = preg_replace("[^&id=*]" ,'',$_SERVER[QUERY_STRING]); But that said I was using an improper modifier. I want to remove "$id=" and whatever number comes after it. Are regexp really as hard as they se...

Regular Expression asp.net. Input could not contain double spaces

How can I write regular expression in C# to validate that the input does not contain double spaces? I am using Regular Expression Validation. However I do not know what is the Validation Expression to get the result. "white snake" : success "white snake" : fail ...

Need MySQL RLIKE expression to exclude certain strings ending in particular characters...

So I've been working with RLIKE to pull some data in a new application and mostly enjoying it. To date I've been using RLIKE queries to return 3 types of results (files, directories and everything). The queries (and example results) follow: **All**: SELECT * FROM public WHERE obj_owner_id='test' AND obj_namespace RLIKE '^user/test/p...

extract domain name from url

How do I extract the domain name from a url using bash? like: http://example.com/ to example.com must work for any tld, not just .com ...

Regular expression to validate a Google Analytics UA Number

It's not 100 percent clear to me that the Google Analytics UA Numbers are always 6 digits, a dash, and 2 digits as Google often mentions in their documentation. There are frequent counter-examples that use fewer than 6 for the account portion and 1-4 for the profile. All of the examples always show numbers but it's not even clear that th...

Java Regex for matching quoted string with escaped quotes

I know there are already many questions like mine but I found no answer which works in Java. So I write a new question. I have text files with content like this: key1 = "This is a \"test\" text with escapes using '\\' characters"; key2 = 'It must work with \'single\' quotes and "double" quotes'; I need a regular expression which mat...

nginx subdomain rewrite

I need a nginx rewrite rule to rewrite from: http://some-keyword.example.com to www.example.com/keyword.php?keyword=$some-keyword while domain without www in front still rewrites to www.example.com and www isn't taken as a keyword. Please could you help me to solve this problem, how to write these two rules? ...

How to extract the first non-Null match from a group of regexp matches in Python?

Suppose I have a regular expression (a)|(b)|(c)|(d). If I apply it to text 'foobar' I get a match object >>> compiled = re.compile('(a)|(b)|(c)|(d)') >>> compiled.search('foobar').groups() (None, 'b', None, None) How do I extract the 'b' from here? Or in general, how do I extract the first match from an unknown number of groups (can h...

PHP preg_replace html comments with empty space

Hi Guys, I have a bit of php code like this: $test = "<!--my comment goes here--> Hello World"; Now i want to strip the whole html comment from the string, i know i need to use preg_replace, but now sure on the regex to go in there. Can anybody help? Thanks ...

preg_match_all and newlines inside quotes

Another noob regex problem/question. I'm probably doing something silly so I thought I'd exploit the general ingenuity of the SO regulars ;) Trying to match newlines but only if they occur within either double quotes or single quotes. I also want to catch strings that are between quotes but contain no newlines. Okay so there's what i g...