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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 22:01:28 2025 UTC