이 방법 이외의 단어를 매치하는 더 좋은 방법은, 문장에서 발생하는 단어를 배열에서 찾으려고하는 것입니다.Perl을 사용하여 문장에서 순차적 단어를 찾는 방법은 무엇입니까?
my $count = 0;
my @strings = (
"i'm going to find the occurrence of two words going if possible",
"i'm going to find the occurrence of two words if impossible",
"to find a solution to this problem",
"i will try my best for a way to match this problem"
);
@neurot = qw(going match possible);
my $com_neu = '\b'.join('\b|\b', @neurot).'\b';
foreach my $sentence (@string){
@l = $sentence =~ /($com_neu)/gi;
foreach my $list (@l){
if($list =~ m/\w['\w-]*/){
print $list;
$count++;
}
}
print $count;
}
출력 :
String 1: going going possible
String 2: going
String 3:
String 4: match
는 빠른 방법으로 저를 도와주세요.
감사합니다.
아마 청소기, 필요하지 않은'\ b' 단지 괄호 주위의 모든 단어, 주위 : '\ B를 ($ com_neu) \ b'. – TLP
데이터와 문장 ('@ neurot '의 단어 수, 문장의 길이 ...)에 대한 정보를 제공해야합니다. – bvr
m/\ w /는 m/\ w [ '\ w -] */will과 동일한 문자열을 모두 찾습니다. 그렇다면 [ '\ w -] * 부분의 요점은 무엇입니까? – tadmc