regex

Using python regex to extract namespaces from C++ sources

Hi, I am trying to extract the namespaces defined in C++ files. Basically, if my C++ file contains: namespace n1 { ... namespace n2 { ... } // end namespace n2 ... namespace n3 { ...} //end namespace n3 ... } //end namespace n1 I want to be able to retrieve: n1, n1::n2, n1::n3. Does someone have any suggestion of how I ...

UK Currency Regular Expression for javascript

Hi I'm after a regular expression that matches a UK Currency (ie. £13.00, £9,999.99 and £12,333,333.02), but does not allow negative (-£2.17) or zero values (£0.00 or 0). I've tried to create one myself, but I've got in a right muddle! Any help greatfully received. Thanks! ...

Getting RegExp result after being used in if-statement

I've seen people do the following: if (/Firefox\/(\+S)/.test(userAgent)) { firefox = RegExp.$1; } I know (sorta) what the regexp does, but I'm not really sure how it can be accessed with RegExp.$1. And as a side note: if (/Win(?:dows )?([^do]{2})\s?(\d+\.\d+)?/.test(ua)) { if (RegExp.$1 == "NT") { switch (RegExp.$2) { What'...

How do I match adjacent pairs of delimiters in php based Perl compatible regex?

I have a string which could contain multiple delimiters right next to each other, for example |||, although it could be any number of adjacent delimiters. I need to replace any place "in between" the adjacent pair with a specific character. These delimiters will only need to match if there is no character between the delimiter, not even...

Regex for refactoring to arrays

I have a very big C programming project that uses thousands of struct variables with this naming convention: specificstruct->x = specificstruct->y + specificstruct->z I want to do some heavy refactoring, namely converting most of these struct members to arrays. The code above would look like this: specificstruct->x[i] = specificstruct...

Regex in Python

Goal: Given a number (it may be very long and it is greater than 0), I'd like to get the five least meaningful digits dropping any 0 at the end of that number. I tried to solve this with regex, Helped by RegexBuddy I came to this one: [\d]+([\d]{0,4}+[1-9])0* But python can't compile that. >>> import re >>> re.compile(r"[\d]+([\d]{0...

PHP regular expression

I'm trying to write a regular expression in PHP. From this code I want to match 'bar'. <data info="foo"> "bar"|tr </data> I tried this two regex, without success. It matches 'foo"> "bar'. $regex = '/"(.*?)"\|tr/s'; $regex = '/"[^"]+(.*?)"\|tr/s'; Anyone can help me? Thank you. ...

Email regular expression

Possible Duplicate: What is the best regular expression for validating email addresses? I know this is a common question, but I still can't seem to find a great regular expression to use when validating email addresses. I don't really have time to go read the spec and write my own. What have ya'll used before, and has it worked...

is there something akin to regEx in applescript, and if not, what's the alternative?

I need to parse the first 10 chars of a file name to see if they are all digits. The obvious way to do this is fileName =~ m/^\d{10}/ but I'm not seeing anything regExy in the applescript reference, so, I'm curious what other options I have to do this validation. ...

How do I parse content with regular expression using jQuery?

I am trying to use jQuery to break right ascension and declination data into their constituents (hours, minutes, and seconds) and (degrees, arc-minutes, and arc-seconds), respectively from a string and store them in variables as numbers. For example: $dec = "-35:48:00" -> $dec_d = -35, $dec_m = 48, $dec_s = 00 Actually, the data resi...

How can I replace all the text before the match in a Perl substitution?

Hi I am reading each line of an input file (IN) and printing the line read to an output file (OUT) if the line begins with one of the patterns, say "ab", "cd","ef","gh","ij" etc. The line printed is of form "pattern: 100" or form "pattern: 100:200". I need to replace "pattern" with "myPattern", i.e. print the current line to FILE but re...

Is this regular expression interview question a fair question for a Senior Programmer position?

Which of the following regular expressions cannot be transformed into one using just the base operators of | and * (Kleene star) and grouping ( () ) * /adt[ui]t+\S?/ /b[^e]ac?h+\s\s\sBALL/i /he{5}[Ly]+o\bwo[^r]L(?!d)/ /ab?c+(de{1,3})/ Would this be a fair question to administer for a Senior Programmer position? ...

Regular Expression to match both relative and absolute URLs

Anyone want to try their hand at coming up with a regex that matches both: /foo/bar/baz.gif /foo/bar/ http://www.foo.com/foo/bar I think it might be impossible to do it with one regex, but you never know. EDIT: To clarify, what I'm trying to do is pick out all URI's from a document (Not a HTML document). ...

Should I avoid regular expressions?

Someone I know has been telling me that RegEx should be avoided, as it is heavyweight or involves heavy processing. Is this true? This made a clap in my ears, ringing my eardrums up until now. I don't know why he told me that. Could it have been from experience or merely 3rd-hand information (you know what I mean...)? So, stated plai...

Regular expression substring replacement in Microsoft Excel

I would like to bulk replace the "07" part of a list of strings (mobile telephone numbers) with the international version "447". The list of strings currently forms a columnn in an Excel spreadsheet. I have the regular expression to match strings requiring modification: ^07[0-9]{9}$ ...but I don't know how to do the replacement that...

check a checkbox with a regex

What would be the correct regex to check wether a checkbox is checked in javascript? update: i know it is usually not done with a regex. But since its part of a form module and all the validations are done with a regex. I thought this could also be checked with a regex. My quyestion is how. ...

Updating email addresses in MySQL (regexp?)

Hi, Is there a way to update every email address in MySQL with regexp? What I want to do is to change [email protected] addresses to [email protected]. Is it possible to do with SQL or should I do it with PHP for example? Thanks! ...

Strip/replace spaces within a string

Give a string "5 900 000" i want to get rid of the spaces using gsub with a following pattern: gsub.(/\s/, ''), but that doesn't seem to work. Nor the gsub.(' ', ''). Any ideas guys (ang girls) ? ...

Trim leading n alpha characters from string

I need to trim the first n alpha characters from a string. Examples: a123456 -> 123456 abc123456 -> 123456 abc123456def -> 123456def Thanks in advance for any help. ...

How to combine RegularExpressionValidator control and RequiredFieldValidator?

I often use regex expression validators that are also a required field. Which leads to what seems like redundant controls on the page. There is no "Required" property of the regex validator which means I need another control. Like this: <asp:TextBox ID="tbCreditCardNumber" runat="server" Width="200"></asp:TextBox> <asp:RegularExpression...