如何匹配Perl中的重复字符? [英] How to match repeat characters in Perl?
本文介绍了如何匹配Perl中的重复字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我是Perl的新手,我正在逐步完成在线教程。我正在尝试计算文件中包含双字母字符串的行。这是我的代码 -
Hello,
I''m new to Perl and I''m stepping through an online tutorial. I''m trying to count the lines in a file that have strings with double letters in them. This is my code -
展开 | 选择 | Wrap | / span> 行号
推荐答案
您好,
我是Perl的新手,我正在逐步完成在线教程。我正在尝试计算文件中包含双字母字符串的行。这是我的代码 -
Hello,
I''m new to Perl and I''m stepping through an online tutorial. I''m trying to count the lines in a file that have strings with double letters in them. This is my code -
展开 | 选择 | Wrap | / span> 行号
。+将匹配行中任何一个或多个字符。它不会匹配相同的重复字符。为此您将使用:
/(.)\1/
或者如果您只想计算重复的单词字符
/(\ w)\1 /
发布您正在使用的在线教程的链接。
.+ would match one or more of any character in the lines. It will not match repeated characters that are the same. For that you would use:
/(.)\1/
or if you only want to count repeated word characters
/(\w)\1/
post a link to the online tutorial you are using.
多数民众赞成........................................
Thats right ........................................
这篇关于如何匹配Perl中的重复字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文