Re: [PHP-DEV] preg_match() option for anchored offset?

2017-06-08 Thread Rasmus Schultz
> You are looking for the \G anchor or the A modifier. Both of these options work great! I've submitted a patch to the manual page with a note explaining these options. Thanks :-) On Wed, Jun 7, 2017 at 10:13 PM, Nikita Popov wrote: > On Wed, Jun 7, 2017 at 10:03 PM,

Re: [PHP-DEV] preg_match() option for anchored offset?

2017-06-07 Thread Nikita Popov
On Wed, Jun 7, 2017 at 10:03 PM, Rasmus Schultz wrote: > What do you think about adding another option to preg_match() to allow the > $offset parameter to be treated as the start anchor? > > The manual proposes to do this: > > $subject = "abcdef"; > $pattern =

Re: [PHP-DEV] preg_match() option for anchored offset?

2017-06-07 Thread Rowan Collins
On 07/06/2017 21:03, Rasmus Schultz wrote: What do you think about adding another option to preg_match() to allow the $offset parameter to be treated as the start anchor? The manual proposes to do this: $subject = "abcdef"; $pattern = '/^def/'; $offset = 3;

[PHP-DEV] preg_match() option for anchored offset?

2017-06-07 Thread Rasmus Schultz
What do you think about adding another option to preg_match() to allow the $offset parameter to be treated as the start anchor? The manual proposes to do this: $subject = "abcdef"; $pattern = '/^def/'; $offset = 3; preg_match($pattern, substr($subject, $offset), $matches); In

[PHP-DEV] preg_match

2011-07-08 Thread Rafael Dohms
I was wondering if anyone ever thought of either fixing or writing a new function that would make preg_match actually work in a way that made sense? right now i need to pass in a optional parameter that will receive the match, in this case one or no match, why should this not be the function's

Re: [PHP-DEV] preg_match

2011-07-08 Thread Nikita Popov
The most common use for preg_match is validation: if (!preg_match('~...~', $string)) { /* do something */ } Here $matches is not required, only the 0/1 return value of preg_match is of interest. Furthermore, even if you need $matches, you should always combine it with an if: if

Re: [PHP-DEV] preg_match

2011-07-08 Thread Rafael Dohms
On Fri, Jul 8, 2011 at 9:20 AM, Nikita Popov nikita@googlemail.com wrote: The most common use for preg_match is validation: if (!preg_match('~...~', $string)) { /* do something */ } Here $matches is not required, only the 0/1 return value of preg_match is of interest. Furthermore, even

Re: [PHP-DEV] preg_match

2011-07-08 Thread Nikita Popov
No, you don't need to initialize $matches. It's passed by reference and thus doesn't need to be initialized. And as I already said: It is good practice to ensure that preg_match actually matched something: if (preg_match(REGEX, $string, $matches)) { // in here $matches is guaranteed to be

Re: [PHP-DEV] preg_match

2011-07-08 Thread Ivan Enderlin @ Hoa
Hi Rafael :-), On 08/07/11 15:18, Rafael Dohms wrote: On Fri, Jul 8, 2011 at 9:20 AM, Nikita Popovnikita@googlemail.com wrote: The most common use for preg_match is validation: if (!preg_match('~...~', $string)) { /* do something */ } Here $matches is not required, only the 0/1 return

Re: [PHP-DEV] preg_match

2011-07-08 Thread Rafael Dohms
Still, this is preg_match it only returns one match, why should i get a array and have to use ugly things like $matches[0] afterwards? It just makes for very ugly syntax and extra code, a simple function would make this cleaner and more intuitive, first time using preg_match is a nightmare. --

Re: [PHP-DEV] preg_match

2011-07-08 Thread Alexey Shein
2011/7/8 Rafael Dohms lis...@rafaeldohms.com.br: Still, this is preg_match it only returns one match, why should i get a array and have to use ugly things like $matches[0] afterwards? It just makes for very ugly syntax and extra code, a simple function would make this cleaner and more

RE: [PHP-DEV] preg_match

2011-07-08 Thread Mike Robinson
On July-08-11 10:01 AM Rafael Dohms wrote: [snip] first time using preg_match is a nightmare. IMHO, preg_match is poetry in motion. Going through a million lines of code replacing ereg[i] with preg_match because it was deprecated in 5.3 - *that* is a nightmare. Best Regards Mike Robinson

Re: [PHP-DEV] preg_match

2011-07-08 Thread Richard Quadling
On 8 July 2011 16:31, Mike Robinson m...@rile.ca wrote: On July-08-11 10:01 AM Rafael Dohms wrote: [snip] first time using preg_match is a nightmare. IMHO, preg_match is poetry in motion. Going through a million lines of code replacing ereg[i] with preg_match because it was deprecated in

Re: [PHP-DEV] preg_match

2011-07-08 Thread Ferenc Kovacs
On Fri, Jul 8, 2011 at 6:09 PM, Richard Quadling rquadl...@gmail.com wrote: On 8 July 2011 16:31, Mike Robinson m...@rile.ca wrote: On July-08-11 10:01 AM Rafael Dohms wrote: [snip] first time using preg_match is a nightmare. IMHO, preg_match is poetry in motion. Going through a million

Re: [PHP-DEV] preg_match and shared libpcre3 bug

2007-11-10 Thread Nuno Lopes
With installing a security update for the pcre3 library on Debian (http://lists.debian.org/debian-security-announce/debian-security-announ ce-2007/msg00177.html), preg_match('|^\(|', 'xxx') suddenly returns 1 instead of 0 using PHP 5.1.6. the correct value is 0, yes. The thing is - I have

[PHP-DEV] preg_match and shared libpcre3 bug

2007-11-09 Thread Matthias Pigulla
I know this is weird and off-topic but I hope that someone here can give me a starting pointer. With installing a security update for the pcre3 library on Debian (http://lists.debian.org/debian-security-announce/debian-security-announ ce-2007/msg00177.html), preg_match('|^\(|', 'xxx') suddenly