Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 多行正则表达式搜索_Regex_Perl_Grep_Textwrangler - Fatal编程技术网

Regex 多行正则表达式搜索

Regex 多行正则表达式搜索,regex,perl,grep,textwrangler,Regex,Perl,Grep,Textwrangler,在SO和Google上进行了大量搜索之后,我提出了一个新问题。我正在与TextWrangler合作,试图编写一个正则表达式,它将为我提供多行模式的最短匹配 基本上 ہے\tVM 是我要查找的字符串(由制表符与其词性标记分隔的阿拉伯语单词)。困难的是,我想搜索包含该字符串的所有单个句子。以下是我到目前为止的情况: /(<Sentence id='\d+'>(?:[^<]|<(?!\/Sentence>))*ہے\tVM(?:[^<]|<(?!\/Sent

在SO和Google上进行了大量搜索之后,我提出了一个新问题。我正在与TextWrangler合作,试图编写一个正则表达式,它将为我提供多行模式的最短匹配

基本上

ہے\tVM
是我要查找的字符串(由制表符与其词性标记分隔的阿拉伯语单词)。困难的是,我想搜索包含该字符串的所有单个句子。以下是我到目前为止的情况:

/(<Sentence id='\d+'>(?:[^<]|<(?!\/Sentence>))*ہے\tVM(?:[^<]|<(?!\/Sentence>))*<\/Sentence>)/

/((?:[^输入中可能会出现更多字符串,因此请搜索所有字符串

我相信你的代码应该是这样的>>

use open ':encoding(utf8)';
use Encode;

binmode(STDOUT, ":utf8");
binmode(STDIN,  ":utf8");

my $word = Encode::decode_utf8("ہے");
my @files = glob("*.posn");
my @matches = ();

foreach my $file (@files) {
  open FILE, "<$file" or die "Error opening file $file ($!)";
  my $file = do {local $/; <FILE>};
  close FILE or die $!;
  my @occurrences = $file =~ /<Sentence id='\d+'>(?:[^<]|<(?!\/Sentence>))*$word\tVM(?:[^<]|<(?!\/Sentence>))*<\/Sentence>/g;
  print STDOUT "$_\n\n\n\n" for (@occurrences);
  push (@matches, "$_\n\n") for (@occurrences);
}

open (OUTPUT, ">matches.txt");
print OUTPUT  "@matches";
close(OUTPUT);
使用open':编码(utf8)';
使用编码;
binmode(标准输出,“:utf8”);
binmode(标准输入“:utf8”);
我的$word=Encode::decode_utf8(“ہے”);
my@files=glob(“*.posn”);
我的@matches=();
foreach my$文件(@files){
打开文件“matches.txt”);
打印输出“@matches”;
关闭(输出);


了解有关正则表达式的更多信息。

您可能想在
时使用
,而不是
如果
;您当前的代码在每个文件中只能报告一个匹配项。很棒!是的,一个文件中可能会出现多次--我认识到了我的严重错误。感谢
我的@occurrencess=$file=~…
,我很高兴我不知道这个结构。
use open ':encoding(utf8)';
use Encode;

binmode(STDOUT, ":utf8");
binmode(STDIN,  ":utf8");

my $word = Encode::decode_utf8("ہے");
my @files = glob("*.posn");
my @matches = ();

foreach my $file (@files) {
  open FILE, "<$file" or die "Error opening file $file ($!)";
  my $file = do {local $/; <FILE>};
  close FILE or die $!;
  my @occurrences = $file =~ /<Sentence id='\d+'>(?:[^<]|<(?!\/Sentence>))*$word\tVM(?:[^<]|<(?!\/Sentence>))*<\/Sentence>/g;
  print STDOUT "$_\n\n\n\n" for (@occurrences);
  push (@matches, "$_\n\n") for (@occurrences);
}

open (OUTPUT, ">matches.txt");
print OUTPUT  "@matches";
close(OUTPUT);