如何使用perl提取长字符串中的大写单词
问题描述:
我正在尝试找到一种使用perl从相当长的字符串中仅提取大写单词(至少三个连续的大写字母,再加上数字)的方法。
I am trying to find a way to extract only upper case words (at least three consecutive upper characters, plus numbers) from quite a long string using perl.
示例:
"Hello world, thank GOD it's Friday, I can watch EPISODE4"
输出:
"GOD EPISODE4"
出于某些原因,我无法上场用明智的方式做到这一点,有什么想法吗?谢谢!
For some reason I cannot come up with a sensible way to do this, any ideas? Thanks!
答
使用字符类:
my @matches = ( $string =~ /\b[[:upper:]|[:digit:]]{3,}+\b/g );
say join " - ", @matches;
(您说的是大写字符和数字。您没有指定在哪里
(You stated uppercase characters and numbers. You didn't specify where the number would be. You also didn't say whether or not I need to do something with the number.
编辑您的问题以包括其他要求。
Edit your question to include other requirements).