我必须从文件中提取具有特定格式的字符串。即字符串格式为1后跟连字符和7位数。
for ex.
#CARES# AR_NUMBER=1-4742637
这里我只需要提取1-4742637。 帮助我,如何提取?
答案 0 :(得分:2)
以下内容将捕获:/\b(1-\d{7})\b/
正如所示:
use strict;
use warnings;
my $text = <<'END_TEXT';
for ex.
#CARES# AR_NUMBER=1-4742637
END_TEXT
if ($text =~ /\b(1-\d{7})\b/) {
print "$1";
}
输出:
1-4742637
答案 1 :(得分:1)
if ($subject =~ m/(1-[\d]+)/) {
# Successful match
} else {
# Match attempt failed
}
(1-[\d]+)
Match the regular expression below and capture its match into backreference number 1 «(1-[\d]+)»
Match the characters “1-” literally «1-»
Match a single digit 0..9 «[\d]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
答案 2 :(得分:0)
答案 3 :(得分:0)
请尝试
$var =~ /1-\d{7}/
匹配次数{}
答案 4 :(得分:0)
1-\d{7}
将选择所需的部分。