![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |
Quote\n\n\b Passt auf eine Wortgrenze (zwischen \w und \W)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl
use warnings;
use strict;
my $word = "WORT";
my $otherword = "ANDRENWORT";
my @satz = ();
$satz[0] = "Ein Text mit einem WORT und noch einem ANDRENWORT sowie einem ANDRENWORT.";
$satz[1] = "Ein Text mit einem WORT und noch einem WORT sowie einem ANDRENWORT.";
$satz[2] = "Ein Text mit einem ANDRENWORT und noch einem WORT sowie einem ANDRENWORT.";
$satz[3] = "Ein Text mit einem ANDRENWORT und noch einem ANDRENWORT sowie einem WORT.";
$satz[4] = "WORT und ein Text mit einem ANDRENWORT und noch einem ANDRENWORT sowie einem WORT";
foreach(@satz) {
print $_."\n";
if($_ =~ /(^.*?)\b$word\b.*/) {
print $1."\n";
}
if($_ =~ /.*(\b$word\b(.*?)\b$otherword\b).*/) {
print $2."\n";
}
print "__\n";
}
$word = quotemeta($word);
1
2
3
4
5
6
7
8
9
10
11
quotemeta EXPR
quotemeta
Returns the value of EXPR with all non-"word"
characters backslashed. (That is, all characters
not matching "/[A-Za-z_0-9]/" will be preceded by a
backslash in the returned string, regardless of any
locale settings.) This is the internal function
implementing the "\Q" escape in double-quoted
strings.
If EXPR is omitted, uses $_.
![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |