Bug #68810 [Opn->Nab]: i guess i have found some problem with regular expressions

From: Date: Mon, 12 Jan 2015 19:08:38 +0000
Subject: Bug #68810 [Opn->Nab]: i guess i have found some problem with regular expressions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189910@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68810&edit=1 ID: 68810 Updated by: requinix@php.net Reported by: andrecamargotii at gmail dot com Summary: i guess i have found some problem with regular expressions -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Arch linux PHP Version: 5.6.4 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That's right: your regex wasn't accepting the underscore that was part of your input. The first matched because you didn't say the regex has to match the entire line, which it won't do unless you explicitly tell it to with ^ and $ anchors. Previous Comments: ------------------------------------------------------------------------ [2015-01-12 12:30:42] andrecamargotii at gmail dot com Description: ------------ sorry for the english i wrote this script $lines = file( $this->file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); foreach ( $lines as $line ) { $numline = $numline+1; if( preg_match( '/new\s?[a-z0-9]+\s?/i', $line)) { echo "ok $numline";} } } and $this-file refers to an file where i wrote this: new CR_a123) the script print in the screen ok followed by number of the line (wrong) if i change the script to this $lines = file( $this->file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); foreach ( $lines as $line ) { $numline = $numline+1; if( preg_match( '/new\s?[a-z0-9]+\s?\)/i', $line)) { echo "ok $numline";} } } the script don't print anything (right) thanks for the help the first script was worng because the expression have an underscore, and in script i especified that can be only numbers and letters. the second script is correct because the script cannot output ok. i change the second script to: $lines = file( $this->file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); foreach ( $lines as $line ) { $numline = $numline+1; if( preg_match( '/new\s?[a-z0-9_]+\s?\)/i', $line)) { echo "ok $numline";} } } the third script prints ok (right) now i have put underscore in the regular expression, so now the script can print ok. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68810&edit=1

« previous php.bugs (#189910) next »