regex

Pcrepp - Perl Regular Expression syntax to match host name

Possible Duplicate: The Hostname Regex I'm trying to use pcrepp (PCRE) to extract hostname from url. the pcre regular expression is as same as Perl 5 regular expression. for example: url = "http://www.pandora.com/#/volume/73"; // the match will be "http://www.pandora.com/". I can't find the correct syntax of the regex for ...

How do I match a quoted string followed by a string in curly brackets?

I need a regex expression for matching a string in quotes and then a white space then a round bracket then a curly bracket. For example this is the text I want to match in Java: "'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)} What would the regex for this be? Sorry, but I'm just really lost. I tried a lot of different things b...

Turning HTML character entities to 'regular' letters... why is it only partially working?

I'm using all of the below to take a field called 'code' from my database, get rid of all the HTML entities, and print it 'as usual' to the site: <?php $code = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $code); $code = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $code); $code = html_entity_decode($code); ?> H...

Convert Regular Expression pattern from Javascript to PCRE (perl)

Hello. This is my javascript regex pattern: url = "http://www.amazon.com/gp"; hostname = /^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?@)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??([^#]+)?#?(\\w*)/.exec(url) || []; // would return "www.amazon.com" the above regex extracting the hostname from a given url. I ...

Working with GNU regex functions in C or C++

Can anyone give me complete example program how to work with GNU regex functions in gcc C or C++ (http://docs.freebsd.org/info/regex/regex.info.GNU_Regex_Functions.html), with re_pattern_buffer, re_compile_fastmap? For example, translate this small Python program: import re unlucky = re.compile('1\d*?3') nums = ("13", "31", "777", "1...

Need help with regex to remove square brackets and anything between

How can I remove text from between square brackets and the brackets themselves? For example, I need hello [quote="im sneaky"] world to become hello world Here's what I'm trying to use, but it's not doing the trick preg_replace("/[\[(.)\]]/", '', $str); I just end up with hello quote="im sneaky" world Thanks ...

PCRECPP (pcre) extract hostname from url code problem

I have this simple piece of code in c++: int main(void) { string text = "http://www.amazon.com"; string a,b,c,d,e,f; pcrecpp::RE re("^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?@)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??([^#]+)?#?(\\w*)"); if(re.PartialMatch(text, &a,&b,&c,&d,&e,&f))...

How do you replace double quotes with a blank space in Java?

For example: "I don't like these "double" quotes" and I want the output to be I don't like these double quotes ...

Would a regex like this work for these lines of text?

Regex: String regexp = "([0-9.]{1,15})[ \t]*([0-9]{1,15})[ \t]*([0-9.]{1,15})[ \t]*(\"(.*?)\"\\s+\\((\\d{4})\\)\\s+\\{(.*?)\\})"; Text: 1000000103 50 4.5 #1 Single (2006) 2...1.2.12 8 2.7 $1,000,000 Chance of a Lifetime (1986) 11..2.2..2 8 5.0 $100 Taxi Ride (2001) ....13.311 9 7.1 $100,000 Name Th...

How can I validate EU Social Security Number?

Is there a regex for social security number (id) in EU? ...

Why exception with this regular expression pattern (tr1::regex)?

Hi everyone, I came accross a very strange problem with tr1::regex (VS2008) that I can't figure out the reason for. The code at the end of the post compiles fine but throws an exception when reaching the 4th regular expression definition during execution: Microsoft C++ exception: std::tr1::regex_error at memory location 0x0012f5f4.....

Javascript regular expression URL alteration

I have a URL like /admin/editblogentry?page=3&color=blue I want to alter the 'page' in the url to 1 so that the url becomes /admin/editblogentry?page=1&color=blue What is the best way to accomplish this using javascript? ...

Regular expression to modify the line following a line that begins with a key phrase?

I have a huge file that has some lines that need to have a line of dashes underneath them followed by an empty line. All of these lines start with the same particular word pattern ("Dollars required for") but every other word on the line is different from one line to the next. For example, the document looks like this at the moment: ...

Perl Oneliner to parse multiple conditions in regex

I have a file that contain lines that looks like this: >AF001546_1 [88 - 462] 1 MGQQ >AF001543_1 [88 - 261] ACGT Not that each line can contain 6 OR 5 fields. What I want to do is to capture Fields 1,2,3(num only), 5(num only) and last field (ACGT or MGOQ strings). So the expected output is this: >AF001546_1 88 462 MGQQ >AF001543_1 ...

Regular expression to replace multiple lines that match a pattern

If I have a bunch of text like this The cat sat on the mat Expropriations for international monetary exchange ( Currenncy: Dollars, Value: 50,000) The cat sat on the mat Expropriations for international monetary exchange ( Currenncy: Yen) The cat sat on the mat Is there a Regular Ex...

Regular expression to modify a line that contains only a single word at the start

I have a text file in which any line that starts with a single word and has no other characters after that should be enclosed inside caret characters. For example, a line that contains only the following 6 characters (plus the newline): France should be replaced with a line that consists of only the following 8 characters (plus the n...

How do I split a string in C# based on letters and numbers.

How can I split a string such as "Mar10" into "Mar" and "10" in c#? The format of the string will always be letters then numbers so I can use the first instance of a number as an indicator for where to split the string. ...

Regular expression to wrap matching lines inside pound signs but not leading whitespace

Is there a Regular Expression I could use in the Find/Replace feature of my text editor (Jedit) to do the following: Match any lines in a text file that meet these criteria: The line ends with a closing parenthesis An opening parenthesis exists somewhere on the same line If it matches I need to wrap all of the text on the line - but...

Match start and end of file in python with regex

I'm having a hard time finding the regex for the start and end of a file in python. How would I accomplish this ? ...

Regular Expression

I want regular expression that checks that the string doesnt start with an empty space. Some what like this i want to do : Is the below ValidationExpression right for it : string ValidationExpression = @"/^[^ ]/"; if (!String.IsNullOrEmpty(GroupName) && !Regex.IsMatch(GroupName, ValidationExpression)) { } ...