regex

How to detect an invalid C escaped string using a regular expression?

I would like to find a regular expression (regex) that does detect if you have some invalid escapes in a C double quoted escaped string (where you can find double quotes only escaped). I consider valid \\ \n \r \" (the test string is using ") A partial solution to this is to use (?<!\\)\\[^\"\\nr] but this one fails to detect bad escap...

What is /^ and /i in Perl?

Recently I downloaded a source (LevBot) and then I see this line: } elsif($text =~ /^slaps $levbot_nick/i) { But what /^ and /i do? Why to use they? I think this is regular expression, I'm right? ...

Best practices for email address validation (including the + in gmail addresses)

I know there are a lot of questions on here about email validation and specific RegEx's. I'd like to know what the best practices are for validating emails with respect to having the [email protected] trick (details here). My current RegExp for JavaScript validation is as follows, but it doesn't support the extra + in the h...

Regex help please

I have the following regex: var regex = @"\[(\w+)( (\w+)=""([^""]+)"")*\]"; This regex matches strings like: [Name Parameter="Value" Parameter2="vv"] [A B="3"] So, first of all, I want to extend it so it'll match strings, when, if the value is one word, so you don't need a quotation mark before/after the value. For example: [Name ...

regular expression to parse links from html code

Possible Duplicate: Regex to get the link in href. [asp.net] I'm working on a method that accepts a string (html code) and returns an array that contains all the links contained with in. I've seen a few options for things like html ability pack but It seems a little more complicated than this project calls for I'm also interes...

.NET regular expression to match "anything else"

I am constructing a regular expression that will contain a number of groups in a logical OR relationship ... (group A)|(group B)|(group C) This expression already successfully matches its intended sub-strings, but I need to add a final group that will match anything else, with the result that the target string will be entirely consume...

Python 3 (2.6+) str.format() and regular expressions

Using str.format() is the new standard for formatting strings in Python 2.6, and Python 3. I've run into an issue when using str.format() with regular expressions. I've written a regular expression to return all domains that are a single level below a specified domain or any domains that are 2 levels below the domain specified, if the 2...

Finding an html element ID based on a text displayed.

Hi, Given the following html: <div id="f52_lblQuestionWording" title="" style="width:auto;height:auto; display: inline; overflow: hidden;" >Home telephone</div> I want to automatically get the ID of the container div element using the "Home telephone" string, does anyone know how I can do this via a regular expression? The string t...

Regex parsing multiple elements, with the first one being optional

I am trying to integrate my timesheets app with Fogbugz by using a text pattern in the time entry's notes to indicate that work was done on a case. Scenario A: If work was done on case#123, the note would be: [123] Rewrote javascript code. Desired output: Case: 123 Note: Rewrote javascript code. Scenario B: If work was not related to ...

Given an array, how to remove the white spaces before and after a single occuring semicolon & and make other multiple whitespaces turn into one?

Array example entry: test : title=Diet Coke Becomes test:title=Diet Coke ...

Regex Reference Cards

Hi, Where an I find some nice regex reference cards that I can download/buy? ...

regex to get value of inside a particular TD in HTML

I need to fetch a particular element in HTML that has the following pattern: (C#) <td class="blah" ...........>Some text blah: page x of xx<br> I need to get the value of xx. The only thing that is constant in the above pattern is: its a TD element it has class="blah" in it it has the text pattern ": page x of xx You can assume t...

C++ implementing a regex map

I have mutliple regex expressions, each mapped to a different object. After passing in a string, I want to loop through each regex expression until one evaluates to true, then I would like to return the mapped object. What is the best way to implement this in C++? Is there a boost object available for this? ...

Regular expression help

Need regular expression to change below url abc.aspx?str=blue+lagoon&id=1234 to /blog/blue-lagoon/ Appreciate all your help. ...

jquery regular expression with custom messages

I need to implement a regular expression in my asp.net mvc(C#) application using jquery. I have a sign in form, in which i need to validate the fields with the required and regular expression. Putting more clearly, I have Username and Password fields in my Sign in form. I need to validate as required first, and if the user entered any ...

JavaScript Regular Expressions - Forcing case when replacing

Does the JavaScript regex standard support forcing case when doing a search/replace? I am generally aware of the \u etc. options for forcing the case of a capture group in the replacement portion of a regular expression. I am unable to figure out how to do this in a JavaScript regex though. I do not have access to the JavaScript code ...

C# Regular Expression

Can you explain me what is the meaning of this regular expression. What would be the string which matches to this expression. Regex(@"/Type\s*/Page[^s]"); what is @ symbol?? Thanks in advance. Please provide full explaination. What would be the string which matches to this expression. ...

regex for capturing digits and digit ranges

i have the following string Fat mass loss was 2121,323.222 greater for GPLC (2–2.4kg vs. 0.5kg) i want to capture 212,323.222 2-2.24 0.5 i.e. i want the above three results from the string, can any one help me with this regex ...

PHP small problem with regular expressions

Hello people, I use this for clean a string: $clean = preg_replace("/[^a-zA-Z0-9\/_.;|+ -]/", '', $str); Works good, but I need add into the regex the char '&' too, I tried to add: $clean = preg_replace("/[^a-zA-Z0-9\/_.;&|+ -]/", '', $str); or $clean = preg_replace("/[^a-zA-Z0-9\/_.;\&|+ -]/", '', $str); but this doesn't work, ...

Escaping \ in regular expressons in Ruby

Hi All, I'm new to ruby and came across an interesting problem yesterday. I was parsing a file and some lines of the file ended with "\". I wanted to use gsub to find and replace it. I tried '\' and /\/ and neither one correctly matched "\". I ended up getting around it by using a combination of chop and strip but it left me thinking ...