regex

Basic Boost Regex question

I'm trying to write some c++ code that tests if a string is in a particular format. In this program there is a height followed by some decimal numbers: for example "height 123.45" or "height 12" would return true but "SomeOtherString 123.45" would return false. My first attempt at this was to write the following: string action; cin >> ...

Regular Expressions, Checking for a range of occurrences

I have a phone number I want to match against a regular expression. The format of the phone number must match this: (123) 123-4567 x12345 The extension is optional. Also the extension must contain 1-5 numbers. Below is a regular expression I wrote that works. ^\(\d{3}\) \d{3}-\d{4}( x\d\d?\d?\d?\d?)?$ I was wondering if there is a b...

Simple java regular expression replace question.

I have a simple xml file and I want to remove everything before the first <item> tag. <sometag> <something> ..... </something> <item>item1 </item> .... </sometag> The following java code is not working: String cleanxml = rawxml.replace("^[\\s\\S]+<item>", ""); What is the correct way to do this? And how do I address t...

jquery, Regexp, make dynamic url

Hi , I need a regexp help, because for me it will take a lot of time , for you some minutes:) I have youtube a URL : http://www.youtube.com/watch?v=9_Hd8hXhg7o&amp;feature=youtube_gdata I can't add this in embed object , for embed I have to change in this URL : http://www.youtube.com/v/9_Hd8hXhg7o&amp;hl=en_US&amp;fs=1&amp; It...

Is there a compelling reason to use quantifiers in Perl regular expressions instead of just repeating the character?

I was performing a code review for a colleague and he had a regular expression that looked like this: if ($value =~ /^\d\d\d\d$/) { #do stuff } I told him he should change it to: if ($value =~ /^\d{4}$/) { #do stuff } To which he replied that he preferred the first for readability (I find the second more readable, but that'...

What is the regex patten for this?

Hi there, I am looking for a regex pattern to find all the content b/w curly brackets. For example, there is a string. $string = {xxx yyy zzz} I want to find a regex pattern so that it can extract the "xxx yyy zzz" out but no {}. Thank you very much for your help. ...

UNIX-style RegExp Replace running extremely slowly under windows. Help? EDIT: Negative lookahead assertion impacting performance.

I'm trying to run a unix regEXP on every log file in a 1.12 GB directory, then replace the matched pattern with ''. Test run on a 4 meg file took about 10 minutes, but worked. Obviously something is damaging performance by several orders of magnitude. UPDATE: I am noticing that searching for ^(155[0-2]).*$ takes ~7 seconds in a 5.6 MB f...

Removing non-alphanumeric characters from a string

I have a string in PHP and I want it to match the regex [A-Za-Z0-9]. How can I do this? ...

Boost Regex throwing an error

Hi ALL, I have the following error when I try to compile my code in g+ compiler using eclipse In function `ZSt19__iterator_categoryIPKSsENSt15iterator_traitsIT_E17iterator_categoryERKS3_': C:/Program Files (x86)/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algobase.h:(.text$_ZN5boost11basic_regexIcNS_12reg...

xVal and Regular Expression Match

I am using xVal to validate my forms in asp.net MVC 1.0 Not sure why my regular expression isn't validating correctly. It does NOT validate with an empty value It does NOT validate with the value of "1", "12", "123", or "1234" It validates with the value of "12345" It validates with the value of "12345 " It validates with the value of...

Find all substrings between two strings

I need to get all substrings from string. For ex: StringParser.GetSubstrings("[start]aaaaaa[end] wwwww [start]cccccc[end]", "[start]", "[end]"); that returns 2 string "aaaaaa" and "cccccc" Suppose we have only one level of nesting. Not sure about regexp, but I think it will be userful. ...

Function to hide sloppy phone numbers..

I need to hide phone numbers (and maybe other contact details) in user generated content to protect my users from anonymous web. Input is very random, therefore I'd be looking to replace anything that looks like a phone number (e.g.: string of 3 or more numbers) with just dots, and also perhaps remove some exotic notations of e-mail add...

What is a Perl regex for finding the first non-consecutively-repeating character in a string?

Your task, should you choose to accept it, is to write a Perl regular expression that for a given string, will return the first occurence of a character that is not consecutively duplicated. In other words, both preceded AND succeeded by characters different from itself (or start/end of string respectively). Example: IN: aabbcdecc OUT:...

Regular Expression Longest Possible Matching

So I have an input string which is a directory addres: Example: ProgramFiles/Micro/Telephone And I want to match it against a list of words very strictly: Example: Tel|Tele|Telephone I want to match against Telephone and not Tel. Right now my reg looks like this: my( $output ) = ( $input =~ m/($list)/o ); The regex above will match...

regular expression to find all cell addresses in string

I have a string which may contain cell address, which is look like: A1, B34, Z728 - only capital letters and AA3, ABA92, ZABC83 - there may be several letters before Integer number. The typical source string is look like: =3+7*A1-B3*AB28 I need to get collection of all cells in the string: A1, B3, AB28 I tried to use Regex.Matches ...

php PHPExcel split Excel cell coordinate

currently, I used PHPExcel to import excel file, there is a function $cell->getCoordinate(); I would like to ask any solution for split the cell coordinate alphabet and integer? e.g A1, A2, I need to know currently which row, and until which column. I do some research about split, but not luck for it. Any idea? ...

What's the fastest way to check if a word from one string is in another string?

I have a string of words; let's call them bad: bad = "foo bar baz" I can keep this string as a whitespace separated string, or as a list: bad = bad.split(" "); If I have another string, like so: str = "This is my first foo string" What's the fasted way to check if any word from the bad string is within my comparison string, and ...

PHP regular expression find and append to string

I'm trying to use regular expressions (preg_match and preg_replace) to do the following: Find a string like this: {%title=append me to the title%} Then extract out the title part and the append me to the title part. Which I can then use to perform a str_replace(), etc. Given that I'm terrible at regular expressions, my code is faili...

Regex for removing leading and trailing carriage returns and line feeds from a sentence.

Also is it possible to combine this with removing periods from within the string? The sentence may have spaces which I'd like to keep. ...

Regular Expression to replace the numbers in a file

Hi all There are a lot of numbers like 200 20.5 329.2...in a file. Now, I need replace every number A with A*0.8. Is there any simple method to replace original value with another based on original value? Best Regards, ...