如何使用单个正则表达式匹配以“/ 1”或“/ 2”结尾的行?(How can I match lines ending with “/1” or “/2” using a single regular expression?)
我正在解析文本行,并尝试使用单个正则表达式从行中删除尾部的“/ 1”或“/ 2”。
现在我有这个,它正常工作:
$id =~ s/\/1$//; $id =~ s/\/2$//;如何将这些组合成一行? 我尝试使用大括号,但我没有让它工作。
I'm parsing lines of text and trying to remove the trailing "/1" or "/2" from the lines with a single regular expression.
Right now I have this and it works correctly:
$id =~ s/\/1$//; $id =~ s/\/2$//;How can I combine these into a single line? I tried using braces but I haven't gotten it to work.
最满意答案
$id =~ s/\/[12]$//;使用匹配1或2的字符类[12] 。
$id =~ s/\/[12]$//;using the character class [12] which matches either a 1 or a 2.
更多推荐
发布评论