php 法语字符的正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1922097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
regular expression for French characters
提问by nextu
I need a function or a regular expression to validate strings which contain alpha characters (including French ones), minus sign (-), dot (.) and space (excluding everything else)
我需要一个函数或正则表达式来验证包含字母字符(包括法语字符)、减号 (-)、点 (.) 和空格(不包括其他所有内容)的字符串
Thanks
谢谢
回答by Amber
/^[a-zàa?éèê?????ùü???? .-]*$/i
Use of /ifor case-insensitivity to make things simpler. If you don't want to allow empty strings, change *to +.
使用/ifor 不区分大小写使事情变得更简单。如果您不想允许空字符串,请更改*为+.
回答by Sam G
Simplified solution:
简化的解决方案:
/^[a-zA-Zà-?-. ]*$/
/^[a-zA-Zà-?-. ]*$/
Explanation:
解释:
^ Start of the string
[ ... ]* Zero or more of the following:
a-z lowercase alphabets
A-Z Uppercase alphabets
à-? Accepts lowercase and uppercase characters including letters with an umlaut
- dashes
. periods
spaces
$ End of the string
^ Start of the string
[ ... ]* Zero or more of the following:
a-z lowercase alphabets
A-Z Uppercase alphabets
à-? Accepts lowercase and uppercase characters including letters with an umlaut
- dashes
. periods
spaces
$ End of the string
回答by John Feminella
Try:
尝试:
/^[\p{L}-. ]*$/u
This says:
这说:
^ Start of the string
[ ... ]* Zero or more of the following:
\p{L} Unicode letter characters
- dashes
. periods
spaces
$ End of the string
/u Enable Unicode mode in PHP
回答by Tom Auger
The character class I've been using is the following:
我一直在使用的字符类如下:
[\wà-üà-?où-???]. This covers a slightly larger character set than only French, but excludes a large portion of Eastern European and Scandinavian diacriticals and letters that are not relevant to French. I find this a decent compromise between brevity and exclusivity.
[\wà-üà-?où-???]. 这涵盖了比仅法语稍大的字符集,但排除了大部分与法语无关的东欧和斯堪的纳维亚变音符号和字母。我发现这是简洁性和排他性之间的一个不错的妥协。
To match/validate complete sentences, I use this expression:
[\w\s.,!?:;&#%''"()??à-üà-?où-???], which includes punctuation and French style quotation marks.
为了匹配/验证完整的句子,我使用以下表达式:
[\w\s.,!?:;&#%''"()??à-üà-?où-???],其中包括标点符号和法式引号。
回答by Alex Brasetvik
[\w .-]should suffice, but you'll need to have \wconsider the locale and/or put it into Unicode mode, so \wmatches what Unicode defines as alpha-numeric characters. How to do that in PHP is probably just a Google away.
[\w .-]应该足够了,但是您需要\w考虑语言环境和/或将其置于 Unicode 模式,以便\w匹配 Unicode 定义为字母数字字符的内容。如何在 PHP 中做到这一点可能只是谷歌。
回答by PyWebDesign
This line of regex pass throug all of cirano de bergerac french text: (you will need to remove markup language characters http://www.gutenberg.org/files/1256/1256-8.txt
这行正则表达式传递了所有 cirano de bergerac 法语文本:(您需要删除标记语言字符 http://www.gutenberg.org/files/1256/1256-8.txt
^([0-9A-Za-z\u00C0-\u017F\ ,.\;'\-()\s\:\!\?\"])+
回答by nickf
This might suit:
这可能适合:
/^[ a-zA-Z\xBF-\xFF\.-]+$/
It lets a few extra chars in, like ÷, but it handles quite a few of the accented characters.
它允许输入一些额外的字符,例如 ÷,但它可以处理相当多的重音字符。
回答by Pragati Sureka
/[A-Za-z-\.\s]/ushould work.. /u switch is for UTF-8 encoding
/[A-Za-z-\.\s]/u应该可以工作.. /u 开关用于 UTF-8 编码

