在Perl中等于重新匹配在Python中?

2024-06-06 13:21:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Python中复制Perl-Fathom。此步骤更正某些单词组合的音节计数。等于重新匹配在Python中?重新匹配只寻找第一个实例。谢谢您!你知道吗

 @SubSyl = (
           'cial',
           'tia',
           'cius',
           'cious',
           'giu',              
           'ion',
           'iou',
           'sia$',
           '.ely$',             
           '[^td]ed$',          
          );

 foreach (@SubSyl) {
          $syl-- if $word =~ /$_/;
        }

Tags: 实例步骤单词perl计数音节iouion
2条回答

当然不是^{}。这有点困难,但是re.match只匹配从字符串开头开始的模式。你知道吗

If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding match object. Return None if the string does not match the pattern; note that this is different from a zero-length match.

^{}更可能是您正在寻找的(除非您的regex模式恰好总是匹配字符串的开头)。你知道吗

=~是绑定运算符。它可以绑定匹配、替换或音译。我想只有第一个可以等同于Python中的匹配,但是似乎您需要re.search,因为与//的匹配没有锚定在字符串的开头。你知道吗

相关问题 更多 >