如何使用perl提取长字符串中的大写单词 [英] How to extract upper case words within a long string using perl

查看:239
本文介绍了如何使用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).

这篇关于如何使用perl提取长字符串中的大写单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆