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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kulakov74 at yandex dot ru
New email:
PHP Version: OS:

 

 [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: Fri Apr 19 16:01:27 2024 UTC