php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61958 Trailing linebreak ignored
Submitted: 2012-05-06 04:19 UTC Modified: 2012-05-06 06:06 UTC
From: kulakov74 at yandex dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.12 OS: Linux, Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 37 = ?
Subscribe to this entry?

 
 [2012-05-06 04:19 UTC] kulakov74 at yandex dot ru
Description:
------------
I want to check if a string is a single wordcharacter but even it has a trailing linebreak preg_match() returns 1. 

Test script:
---------------
echo preg_match('~^\w$~', "a\n");

Expected result:
----------------
0

Actual result:
--------------
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-06 04:35 UTC] kulakov74 at yandex dot ru
Sorry, the title should be "preg_match() ignores trailing linebreak"
 [2012-05-06 05:07 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-05-06 05:07 UTC] rasmus@php.net
This is documented behaviour and consistent with every Perl-style regex 
implementation in every language. Use the 'D' modifier if you want to change that 
behaviour. See http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

eg. 

echo preg_match('~^\w$~D', "a\n");
 [2012-05-06 06:06 UTC] kulakov74 at yandex dot ru
Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 21:01:31 2024 UTC