(?(?<=\w)(?!\w)|(?=\w)) # \b equivalent
####
(?(?<=\w)(?=\w)|(?!\w)) # \B equivalent
####
# \b equivalent:
(?(?<= \w) # if there is a word character left
(?! \w) # then there must be no word character right
| (?= \w) # else there must be a word character right
)
# \B equivalent:
(?(?<= \w) # if there is a word character left
(?= \w) # then there must be a word character right
| (?! \w) # else there must be no word character right
)
####
(?(DEFINE)
(? [\p{Greek}\p{Inherited}] )
(? [^\p{Greek}\p{Inherited}] )
(?
(?(?<= (?&greeklish))
(?! (?&greeklish))
| (?= (?&greeklish))
)
)
(?
(?(?<= (?&greeklish))
(?= (?&greeklish))
| (?! (?&greeklish))
)
)
)
####
sub IsGreeklish {
return <<'END';
+utf8::IsGreek
+utf8::IsInherited
END
}
####
# space boundary
(?(?<= \S) # if there is a nonspace character left
(?! \S) # then there must be no space character right
| (?= \S) # else there must be a space character right
)
####
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
my $space_edge = qr{
(?(?<= \S) # if there is a nonspace character left
(?! \S) # then there must be no space character right
| (?= \S) # else there must be a space character right
)
}x;
while () {
my $edges = 0;
for my $str ( "foo", "()" ) {
my $qstr = quotemeta($str);
unless (/$qstr/) {
#print "MISSING $str in: $_";
next;
}
if (/${space_edge}${qstr}/) {
$edges++;
print "$str EDGE LEFT: $_"
}
if (/${qstr}${space_edge}/) {
$edges++;
print "$str EDGE RIGHT: $_"
}
unless ($edges) {
print "$str UNEDGED: $_";
}
}
}
exit;
__END__
Put your foo in your pocket.
Put your foo() in your pocket.
Good food was had by all.
What fools these mortals be!
food is good to have.
That's a major snafoo there.
That's a major snafoo.
That's a major snafoo
That's a major snafoo()zle
That's a major snafoo() there.
That's a major snafoo()
####
foo EDGE LEFT: Put your foo in your pocket.
foo EDGE RIGHT: Put your foo in your pocket.
foo EDGE LEFT: Put your foo() in your pocket.
() EDGE RIGHT: Put your foo() in your pocket.
foo EDGE LEFT: Good food was had by all.
foo EDGE LEFT: What fools these mortals be!
foo EDGE LEFT: food is good to have.
foo EDGE RIGHT: That's a major snafoo there.
foo UNEDGED: That's a major snafoo.
foo EDGE RIGHT: That's a major snafoo
foo UNEDGED: That's a major snafoo()zle
() UNEDGED: That's a major snafoo()zle
foo UNEDGED: That's a major snafoo() there.
() EDGE RIGHT: That's a major snafoo() there.
foo UNEDGED: That's a major snafoo()
() EDGE RIGHT: That's a major snafoo()