1
文件看起來像如何使用perl正則表達式匹配這樣的東西?
[N the computer end] [M whatever] [N you look] [N why not]
我只需要在支架與[N
所以這裏開始的話我想獲得電腦端你看爲什麼不 他們可能會或可能不會在同一條線上
我想是這樣的:
if($line =~/\[N(.+?)\]/)
但只匹配每一行的第一個。
文件看起來像如何使用perl正則表達式匹配這樣的東西?
[N the computer end] [M whatever] [N you look] [N why not]
我只需要在支架與[N
所以這裏開始的話我想獲得電腦端你看爲什麼不 他們可能會或可能不會在同一條線上
我想是這樣的:
if($line =~/\[N(.+?)\]/)
但只匹配每一行的第一個。
在正則表達式上使用g
修飾符來查找「g」部落匹配。無論是這樣的:
while ($line =~ /\[N(.+?)\]/g) {
# $1 contains the text between "[N" and "]"
}
或者這樣:
my @matches = $line =~ /\[N(.+?)\]/g;
# @matches contains all of the matching items of text
你需要將其更改爲一個while循環遍歷每個組的比賽。 Perl documentation說明了這一點。