Non Word Boundry "B" metacharacter in Regular Expression.

What is Non Word Boundry?

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"
"/ioB/" - Match boundry between "io" and "x".
"/oxB/" - Unmatch as its nonword boundry between "ox", """.

PHP Example:


<?php
$name = "sampaulchristdany";
if (preg_match("/samB/", $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:programfilesperlbinperl
print "content-type: text/htmlnn";
$name= "sam-paul-christ-dany";
if ($name =~ m/samBpaul/)
{print "The name format matched!";}
else
{print "The name format not matched!";}
Result :

The name format not matched!

In the above example the pattern "samBpaul" does not match since the word boundry is found for the word "sam" and "-" which is not word character.

Ask Questions

Ask Question