法语字符的正则表达式

nex*_*xtu 11 php regex

我需要一个函数或正则表达式来验证包含字母字符(包括法语字符),减号( - ),点(.)和空格(不包括其他所有字符串)的字符串

谢谢

Amb*_*ber 21

/^[a-zàâçéèêëîïôûùüÿñæœ .-]*$/i
Run Code Online (Sandbox Code Playgroud)

使用/i不区分大小写使事情变得更简单.如果您不想允许空字符串,请更改*+.

  • 严格来说 - 不是法国人,但OP没有明确地排除非法语人物. (3认同)
  • 或"Je suisunPiñata" (3认同)
  • @kiamluno,除了 ñ french 使用所有其他提到的字符,有些只有几个单词,例如“où”(哪里)或“L'Haÿ-les-Roses”(巴黎附近的城市) (2认同)

Sam*_*m G 6

简化解决方案:

/^[a-zA-ZÀ-ÿ-. ]*$/

说明:

^ 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

  • 我认为“À-ÿ”是错误的。不应该是 `À-Ÿ` ([示例](https://pythex.org/?regex=%5B%C3%80-%C5%B8%5D%2B&test_string=%C3%80%C3%82 %C3%87%C3%89%C3%88%C3%8A%C3%8B%C3%8E%C3%8F%C3%94%C3%9B%C3%99%C3%9C%C5%B8%C3 %91%C3%86%C5%92%C3%A0%C3%A2%C3%A7%C3%A9%C3%A8%C3%AA%C3%AB%C3%AE%C3%AF%C3%B4 %C3%BB%C3%B9%C3%BC%C3%BF%C3%B1%C3%A6%C5%93&ignorecase=0&multiline=0&dotall=0&verbose=0))? (4认同)

Joh*_*lla 5

尝试:

/^[\p{L}-. ]*$/u
Run Code Online (Sandbox Code Playgroud)

这说:

^         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
Run Code Online (Sandbox Code Playgroud)