正则表达式+字符串数组 [英] Regex + Arrays of Strings
本文介绍了正则表达式+字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用一些正则表达式检查一个字符串数组.
我想知道如何从第二次出现的项目中进行搜索.
如果我的文件包含以下字符串的数组:
I have an array of strings I''d like to check using some regular expressions.
I was wondering how to search FROM the second occurrence of an item.
If my file contains an array of these strings:
Green
Blue
Green
Orange
Blue
Yellow
如何从"GREEN"的第二个匹配项的位置中搜索(上面有下划线)?
How would I search FROM the position of the second match of "GREEN" (underlined above)?
open(MYFILE, "C:\\MyFile.txt")||die;
my @lines = <MYFILE>;
foreach $line (@lines){
if($line =~ m/regex pattern/)
{
#search FROM that match for the next thing I need to match
#need code here~
}
else
{
#the regex does not match $line
}
}
推荐答案
line(@lines){ if(
line (@lines){ if(
line =〜m/regex pattern/) { #search从该匹配项中查找我需要匹配的下一件事 #需要这里的代码〜 } 别的 { #正则表达式不匹配
line =~ m/regex pattern/) { #search FROM that match for the next thing I need to match #need code here~ } else { #the regex does not match
行 } }
这篇关于正则表达式+字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文