1. Perl
  2. Regular expression
  3. here

Representing word character delimiters - \b

Use the regular expression character \b to separate word characters.

\b

\b represents the delimiter. The delimiter is the boundary between word characters and whitespace characters. With "ab cd",/\bcd/can represent the 0 character between'' and c.

Word characters are alphanumeric characters and underscores. Whitespace is the character represented by\s, which is a space, tab, or line break.

Example

This is an example using word character delimiters.

use strict;
use warnings;

# Represents a word character delimiter.\b
# (A word character is a character consisting of alphanumeric characters and an underscore)

my $word_space = "ab cd ef";
my $word = "abcd ef";

print "1: Represents word string delimiters\n";
if ($word_space =~ /ab\b/&& $word !~ /Ab\b/) {
  print "/ ab \\b/matches'ab cd ef', but".
    "Does not match'abcd ef'.\n\n";
}

if ($word_space =~ /\bcd\b/&& $word !~ /\Bb\b/) {
  print "/ \\bcd \\b/matches'ab cd ef', but".
    "Does not match'abcd ef'.\n";
}

Related Informatrion