Perl:如何将正则表达式匹配大写?
我正在使用这个正则表达式来查找基因组中的模式。
$string =~ /(?i)a+t?|(?i)t+/g
为了使输出更易于阅读,我想对其进行修改,以便将其匹配的任何 4 到 7 个字符长的内容大写。另外,它不应该弄乱 $+[0]
或 $-[0]
变量。
我输出的方式是根据 '$+[0]' 和 '$+[0]' 从较大的字符串文件中获取子字符串我不想打印出我正在打印的正则表达式匹配出大量的校正器,我希望比赛能够脱颖而出。
如果您确实需要查看我正在处理的代码,您可以在此处获取
I am using this regular expression to find patterns in a genome.
$string =~ /(?i)a+t?|(?i)t+/g
To make the output easier to read I would like to modify it so it capitalizes anything it matches that is 4 to 7 characters long. Also it should not mess up the $+[0]
or $-[0]
variables.
the way i do the output is to get a sub-string from the larger string file based on the '$+[0]' and '$+[0]' i don't want to print out the regex matches i am printing out huge strings of correctors and i want the matches to stand out.
if you really need to see the code I'm working on you can get it here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过适当的测试(针对您的匹配和长度(可能需要带有像 {4,7} 这样的量词的字符组),如果没有示例内容,则由您完成)您可以使用 eval 替换
s/(match)/ uc($1)/eg
它将获取匹配的字符串并将其变为大写,然后用替换项替换匹配项。一如既往,请在
perldoc perlre
perldoc perlre
阅读更多内容。 org/reref" rel="noreferrer">perldoc perlreref
perldoc perlretut
作为旁注,我一直想知道基因组是否是
正则表达式::语法
?With appropriate tests (for your match and for length (character groups with quantifiers like {4,7} are probably needed), without example content this is left to you) you could use an eval substituton
s/(match)/uc($1)/eg
which would take the matched string and make it uppercase then replace the match with the replacement.As always read more at
perldoc perlre
perldoc perlreref
perldoc perlretut
As a sidenote, I have always wondered if Genomes are a good candidate for
Regexp::Grammars
?