Non Word Boundry "\B" metacharacter in Regular Expression.
|
Tutorials

Regular-expression

|
Topic |
What is Non Word Boundry?
|
Warning: include(../adpa.php) [ function.include]: failed to open stream: No such file or directory in /home/myscript/public_html/tutorials/regular-expression/nonword-boundry.php on line 28
Warning: include() [ function.include]: Failed opening '../adpa.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/myscript/public_html/tutorials/regular-expression/nonword-boundry.php on line 28
|
Explanation |
|
A non-word boundry is the boundry between the word characters that should be always between the
characters [a-zA-Z0-9]it give an unmatch if other characters are used.
string = "hiox"
"/io\B/" - Match boundry between "io" and "x".
"/ox\B/" - Unmatch as its nonword boundry between "ox", """.
PHP Example:
<?php
$name = "sampaulchristdany";
if (preg_match("/sam\B/", $name))
echo "Pattern matches!";
else
echo "Pattern not matched!";
?>
Result:
Pattern matches!
In the above example the word "sam" and the next word "paul" is matched,as both are word characters.
Perl Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$name= "sam-paul-christ-dany";
if ($name =~ m/sam\Bpaul/)
{print "The name format matched!";}
else
{print "The name format not matched!";}
Result:
The name format not matched!
In the above example the pattern "sam\Bpaul" does not match since the word boundry is found for
the word "sam" and "-" which is not word character.
|
|