首页 > 解决方案 > 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

标签: regexperl

解决方案


你需要告诉 Perl 你的文件的源代码是 utf8。添加

use utf8;

use strict;

推荐阅读