regex

Mulitple words in any order using regex

As the title says , i need to find 2 specific words in a sentence. But they can be in any order and any casing. How do i go about doing this using regex. E.g. This is a very long sentence used as a test From that sentence i need to extract the words test and long in any order i.e. test can be first or long can be first. UPDATE: What i...

Problems with the following regular expression in RegularExpressionValidator control

I have written the following regular expression. It should match only filenames or folder names that don't end in .aspx. ValidationExpression=".*[^(\.aspx)]$" But it does not work. So, kings of RegEx land, please help. I would also like to invalidate extensions such as .Aspx, .aSPx etc. ( I quickly learned that there are some differen...

What regex will match this?

How do I write a regular expression to match the following CONTEXT_84 = or CONTEXT_5 = thanks ...

Can a URL contain a semi-colon?

I am using a regular expression to convert plain text URL to clickable links. @(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@ However, sometimes in the text, URL are enumerated one per line with a semi-colon at the end. The real URL does not contain any ";". http://www.aaa.org/pressdetail.asp?PRESS_REL_ID=275; http://www.aaa....

Apache ReWrite problem

I'm working on a webpage that takes a URL as a parameter, and would like it to be easily indexed by search engines. One requirement is that each URL appears as a directory. My script is in the format: myscript?url=<a url>&page=1 I'd like redirects to look something like: lookup/<a url>/page:1/ The URL is predictably giving me tro...

Regex matching tags

Hi, I have the following piece of text from which I'd like to extract all the <td ????>???</td> tags <tr id=row509> <td id=serv509 align=center class='style1'>Z Deviazione Tecnico Home verso S24 [ NON USATO ]</td> <td align=center class='style4'>23</td> <td align=center class='style10'>22</td> <td align=center class='st...

Regex implementation that can handle machine-generated regex's: *non-backtracking*, O(n)?

Edit: This question has considerably evolved since I first asked it. See below for two fast+compatible, but not completely fully featured implementations. If you know of more or better implementations, please mention them, there still isn't an ideal implementation here yet! Where can I find reliably fast Regex implementation? Does ...

Find out which group matches in Java regex without linear search?

I have some programmatically assembled huge regex, like this (A)|(B)|(C)|... Each sub-pattern is in its capturing group. When I get a match, how do I figure out which group matches without linearly testing each group(i) to see it returns a non-null string? ...

PHP preg_match question

How can I match the three words in the following string with a Perl compatible regular expression? word1#$word2#$word3 I don't know the actual words "word1, word2 and word3" in advance. I only know the separator, which is #$. And I can't use the word boundary as I have a multibyte encoding. This means for instance that the string can ...

Javascript RegEx: Get all text matches surrounded by some other text?

In JavaScript/JQuery I want to get all the text that is seen between some other text. For example, if the HTML document had: <b class="blah">Blah: Some Text 1</b> <div id="foo"><b class="blah">Blah: Some Text 2</b> I'd like to get an array that has 'Some Text 1' and 'Some Text 2' since they are both in between '<b class="blah">Blah: ...

Why does my preg_replace() on multi-line file contents on Windows fail?

I have a text file Qfile.txt and the contents are follows, and want to create another file with the same informations and but answers are diffrent. Qfile1.txt,Qfile2.txt Qfile.txt Question "What is your age?" Answer "" Question "What you doing?" Answer "" Question "What is you name?" Answer "" Qfile1.txt Question "What is your age...

Regex: how to determine odd/even number of occurences of a char preceding a given char?

I would like to replace the | with OR only in unquoted terms, eg: "this | that" | "the | other" -> "this | that" OR "the | other" Yes, I could split on space or quote, get an array and iterate through it, and reconstruct the string, but that seems ... inelegant. So perhaps there's a regex way to do this by counting "s preceding | and...

is there a plugin for VS2008 that makes it use normal regexs for find/replace?

Re: http://www.codinghorror.com/blog/archives/000633.html Is there a plugin that turns VS2008's non-standard regex find/replace into a more standard version? I didn't find one when I googled for it, so my hopes are not high for this. I hate hate hate having to build a regex in my head and then have to think, "oh, I guess I need to refac...

Composed Regular Expressions - breaking a regex down into a readable form

I was reading an article put together by Martin Fowler regarding Composed Regular Expressions. This is where you might take code such as this: const string pattern = @"^score\s+(\d+)\s+for\s+(\d+)\s+nights?\s+at\s+(.*)"; And break it out into something more like this: protected override string GetPattern() { const string patte...

Javascript Regex: How can I surround all words starting with @ with <b> tags?

I'd like to surround all words in a haystack starting with @ with <b> tags with javascript regex. What pattern would I use? ...

Javascript Regex: surround @_____, #_____, and http://______ with anchor tags in one pass?

Related (but slightly different): http://stackoverflow.com/questions/1216007/surrounding-all-instances-of-and-http-with-a I would like to surround all instances of @_______, #________, and http://________ with anchor tags in one pass. For example, consider this Twitter message: The quick brown fox @Spreadthemovie jumps over t...

regex to match a single character that is anything but a space

I need to match a single character that is anything but a space but I don't know how to do that with regex. ...

Apache mod_rewrite only if request does not start with '/THEMES/'

Hi all SO users! I'm writing a CMS in PHP, and now I'm working at the themes feature. I have a .htaccess file: RewriteEngine ON RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)$ index.php?m=$1 RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)/(.+)$ index.php?m=$1&p=$2 If I have a request to: /page it must load the view function of the class called page. If...

RegExp C# and richtextbox

Hello , Im trying to make the following thing : 1) using regex to match all strings that have the following pattern "@username" << done i got the pattern @([A-z09_-]){4,20} 2) to parse the text from rich text box and to color those patterns "@somethign" in a color 3) make them clickable & when clicked to insert the clicked string in...

Auto-converting numbers to comma-fied versions

Given the following text /feeds/tag/remote-desktop 1320 17007 22449240 /feeds/tag/terminal-server 1328 15805 20989040 /foo/23211/test 1490 11341 16898090 Let's say we want to convert those numbers to their comma-fied forms, ...