regex - RegEx 匹配所有单词字符,以及来自不同语言的变音符号
问题描述
我想检查一个人的名字是否有效。它应该检查拉丁字母,也包括变音符号(即öäüÖÄÜé)。
不幸的是,我没有尝试过任何工作。
关于许多来源(按照一些链接),
https://www.regular-expressions.info/unicode.html
\p{L}
应该工作,但它不适合我。我必须为此去use
图书馆吗?
use strict;
use warnings;
my $test = "testString";
print $1 if ($test =~ m/^(\p{L}+)$/); #testString
$test = "testStringö";
print $1 if ($test =~ m/^(\p{L}+)$/); #no print msg
$test = "testéString";
print $1 if ($test =~ m/^(\p{L}+)$/); #no print msg
解决方案
你需要告诉 Perl 你的文件的源代码是 utf8。添加
use utf8;
后
use strict;
推荐阅读
- kubernetes - Pod 中的 Kubernetes 最佳实践
- python - 如何使用 Python 识别/列出所有 GITHUB webhook (URL)?
- cython - 如何在文档中显示 Cython 函数的参数?
- javascript - struts2表单通过带有隐藏参数的javascript提交
- asp.net - 本地 IIS 8.5 上的简单 ASP.NET Razor 页面 - 500.19 0x8007000d 错误
- ruby - Ruby 仅替换作为哈希传递的多个正则表达式的第一次出现
- highcharts - Highcharts 地图标签并未全部显示
- audiokit - 在 AKAudioPlayer 中使用 AKAudioFile 和 replaceWith 会导致失真吗?
- marklogic - 关于 MarkLogic 内存更新问题
- c++ - 使用模板实参依赖参数编写模板类的构造函数