php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54702 character @ not handled properly with \b
Submitted: 2011-05-10 19:02 UTC Modified: 2011-05-10 23:59 UTC
From: gwbv at yahoo dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: Irrelevant OS: Linux
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: gwbv at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-05-10 19:02 UTC] gwbv at yahoo dot com
Description:
------------
Hi,

I have a problem with the @ character at the end of a word, with the word delimiter \b:

input: i wrote this exampl@ for you

preg_match('/\bexampl@/','i wrote this exampl@ for you') = 1
preg_match('/\bexampl@\b/','i wrote this exampl@ for you') = 0

the second preg_match should also return 1 !!


Test script:
---------------
<?php
 $input='i wrote this exampl@ for you';
 echo "input: ".$input."\n";

 $patt='/\bexampl@/';
 echo "preg_match('".$patt."','".$input."') = ".preg_match($patt, $input)."\n";
 $patt='/\bexampl@\b/';
 echo "preg_match('".$patt."','".$input."') = ".preg_match($patt, $input)."\n";
?>


Expected result:
----------------
for both preg_match, output should be 1, that is, the pattern should be found in the input string

preg_match('/\bexampl@/','i wrote this exampl@ for you') = 1
preg_match('/\bexampl@\b/','i wrote this exampl@ for you') = 1


Actual result:
--------------
preg_match('/\bexampl@/','i wrote this exampl@ for you') = 1
preg_match('/\bexampl@\b/','i wrote this exampl@ for you') = 0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-10 23:59 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-05-10 23:59 UTC] felipe@php.net
This is not a bug.

From PCRE library documentation:
"
   \Biss\B

       which  finds  occurrences  of "iss" in the middle of words. (\B matches
       only if the current position in the subject is not  a  word  boundary.)
"

I.e. \b just makes sense surrounding another word.

  re> /!\b/
data> !
No match
data> 
  re> /a\b/
data> abc a
 0: a
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 09:01:28 2025 UTC