如何删除字符串的最后两个“ - ”字符?(How to remove the last two occurrences of “-” character of a string?)
我有一个格式如下的字符串数组:
Ado-trastuzumab emtansine(HER2)02-22-2013我只想删除最后两个“ - ”符号(从原始字符串的日期部分开始),以便药物名称(Ado-trastuzumab emtansine)不被改变。 现在我的正则表达式会删除所有的“ - ”符号:
foreach my $string (@array) { $string =~ tr/-//d; }我希望输出结果如下所示:
Ado-trastuzumab emtansine(HER2)02222013谢谢您的帮助!
I have an array of strings that are formatted as such:
Ado-trastuzumab emtansine(HER2)02-22-2013I would like to remove the last two "-" symbols only (from the date part of the original string) so that the name of the drug (Ado-trastuzumab emtansine) is not altered. Right now my regex removes all "-" symbols:
foreach my $string (@array) { $string =~ tr/-//d; }I would like the output to instead be the following:
Ado-trastuzumab emtansine(HER2)02222013Thanks for the help!
最满意答案
您可以使用substr作为左值来仅将音译应用于字符串的特定部分:
substr($string, -10, 10) =~ tr/-//d;在这种情况下,字符串的最后10个字母。
You can use substr as an lvalue to only apply the transliteration to a particular part of your string:
substr($string, -10, 10) =~ tr/-//d;In this case, on the last 10 letters of the string.
更多推荐
发布评论