pcre

Extra backslash needed in PHP regexp pattern

When testing an answer for another user's question I found something I don't understand. The problem was to replace all literal \t \n \r characters from a string with a single space. Now, the first pattern I tried was: /(?:\\[trn])+/ which surprisingly didn't work. I tried the same pattern in Perl and it worked fine. After some trial...

UTF-8 characters in preg_match_all (PHP)

I have preg_match_all('/[aäeëioöuáéíóú]/u', $in, $out, PREG_OFFSET_CAPTURE); If $in = 'hëllo' $out is: array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> string(2) "ë" [1]=> int(1) } [1]=> array(2) { [0]=> string(1) "o" [1]=> int(5) } } } The position of o should be 4. I've read about this problem on...

[PHP] regex "/^something/" behavior

In some obscure situations a regular expression like "/^match/" works in the exact oposite way matching a line that is "something else", and the only way to fix it is to put the whole regex inside braces ... "/^(match)/", why is that happening? ...

How to replace ereg?

Hi all, I'm getting the following message for some php I have to use but did not write: Deprecated: Function ereg() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/html2fpdf.php on line 466 This is line 466: if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3)) I tried simply replacing with preg_match, but it couldn't re...

Textmate snippet to format string (regex?)

I'm trying to create a textmate snippet that will transform this: HELLO WORLD<br /> SAY ANYTHING To this: hello world say anything Any help? ...

Why is recursive regex not regex?

I was reading through some of the responses in this question and saw that a few people said that recursive regular expressions were not strictly speaking regular expressions. Why is this? ...

changing time format with preg replace in php

i m just wondering if we can do this with preg replace like if there's time like 1h 38 min can change to 98 mins 2h 20 min can change to 140 mins or just suggest me any other random function to this is simpler way thanks ...

PCRE: Lazy and Greedy at the same time (Possessive Quantifiers)

I am trying to match a series of text strings with PCRE on PHP, and am having trouble getting all the matches in between the first and second. If anyone wonders why on Earth I would want to do this, it's because of Doc Comments. Oh, how I wish Zend would make native/plugin functions to read Doc Comments from a PHP file... The following...

PCRE: Find matching brace for code block

Is there a way for PCRE regular expressions to count how many occurrences of a character it encounters (n), and to stop searching after it has found n occurrences of another character (specifically { and }). This is to grab code blocks (which may or may not have code blocks nested inside them). If it makes it simpler, the input will be...

How do you debug a regex?

Regular expressions can become quite complex. The lack of white space makes them difficult to read. I can't step though a regular expression with a debugger. So how do experts debug complex regular expressions? ...

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 ...

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 ...

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))...

select numbers and insert to database ??

I have a html file that has invoice details I would like to know is there a way that I can retrieve only the invoice numbers and store it separately in my sql database using php? <p>Invoice ID: 0201</p> <p>MID : Q987</p> <p>Desciption: Solid Concrete Blocks</p> <p>Qty: 7478 Blocks </p> <p>&nbsp;</p> <p>Invoice ID: 0324</p> <p>MID : Q44...

preg_match two variables with metacharacters

I have two string variables which are both file paths. The code that worked used ereg which is deprecated, so I'm trying to rewrite it using preg_match: Old code that worked: $path1 = quotemeta($path); ereg("$path1(.*)$", $path2, $matches); Using preg_match which doesn't seem to work: $path1 = quotemeta($path); preg_match("/$path1(....

Delphi - TPerlRegEx / RegExBuddy Problem

I've got a problem with RegEx and Delphi 2k9 (Win32). I get the following Error: First chance exception at $7C812AFB. Exception class Exception with message 'TPerlRegEx.Compile() - Please specify a regular expression in RegEx first'. I've got the latest version of TPerlRegEx from the website. Using its defualt settings (Using DLL) I...

php regex word boundary matching in utf-8

Hi, I have the following php code in a utf-8 php file: var_dump(setlocale(LC_CTYPE, 'de_DE.utf8', 'German_Germany.utf-8', 'de_DE', 'german')); var_dump(mb_internal_encoding()); var_dump(mb_internal_encoding('utf-8')); var_dump(mb_internal_encoding()); var_dump(mb_regex_encoding()); var_dump(mb_regex_encoding('utf-8')); var_dump(mb_regex...

in php how do I use preg replace to turn a url into a tinyurl

I need to convert a string of text containing a long url into the same string but with a tinyurl (using the tinyurl api). eg. convert "blah blah blah /http://example.com/news/sport blah blah blah" into "blah blah blah http://tinyurl.com/yaeocnv blah blah blah". How can it be done? PLEASE NOTE I added a slash before the long url as I'm o...

Is there a way to get the PREMATCH ($`) and POSTMATCH ($') from pcrecpp?

Is there a way to obtain the C++ equivalent of Perl's PREMATCH ($`) and POSTMATCH ($') from pcrecpp? I would be happy with a string, a char *, or pairs indices/startpos+length that point at this. StringPiece seems like it might accomplish part of this, but I'm not certain how to get it. in perl: $_ = "Hello world"; if (/lo\s/) { $...

ereg_replace to preg_replace ?

How can I convert ereg_replace(".*\.(.*)$","\\1",$imgfile); to preg_replace... ? ? I'm having trouble with it? ...