PHP Developers Network
http://forums.devnetwork.net/

confusion about regular expressions in php
http://forums.devnetwork.net/viewtopic.php?f=38&t=142221
Page 1 of 1

Author:  Muhammad Zeeshan [ Sun Jan 24, 2016 5:14 am ]
Post subject:  confusion about regular expressions in php

Can anybody explain me about the following code.
The following code
<?php
$a = 'first line
second line
';
$b = '/l...$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing the output

Array ( [0] => Array ( ) )

instead of
Array ( [0] => Array ( [0] => line ) )

But the following code

<?php
$a = 'first line
second line
';
$b = '/l....$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing
Array ( [0] => Array ( [0] => line ) )
instead of

Array ( [0] => Array ( ) )
Can anyone explain me why it is working in reverse order in my computer?

Author:  requinix [ Sun Jan 24, 2016 5:36 am ]
Post subject:  Re: confusion about regular expressions in php


Author:  b03tz [ Wed May 11, 2016 3:31 pm ]
Post subject:  Re: confusion about regular expressions in php

The one with 3 dots is matching line, the with 4 isn't. At least not on regex101.com

/l...$/m matches "line" (on the first line)
/l...$/ matches "line" (on the second line)

And:
/l....$/m and /l....$/ matches nothing, so indeed, are you sure you got that right?

[edit] wow old thread nvm [/edit]

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/