简体   繁体   English

正则表达式匹配法语和德语字符

[英]Regular expression to match French and German characters

I am parsing the request parameters to find any vulnerable characters to prevent XSS threats. 我正在解析请求参数以查找任何易受攻击的字符以防止XSS威胁。 Our web application supports both French and German languages other than English. 我们的Web应用程序支持除英语之外的法语和德语。 I am using the following regular expression to achieve this, but it fails to handle French and German 我使用以下正则表达式来实现这一点,但它无法处理法语和德语

^[a-zA-Z0-9\r\n\\-=\\*\\.\\?;,+\\/:&_ %@#]*$

Any suggestions on this is highly appreciated 对此的任何建议都非常感谢

Try [\\p{Latin}\\p{Punctuation}\\p{Math_Symbol}] or add more character classes. 尝试[\\p{Latin}\\p{Punctuation}\\p{Math_Symbol}]或添加更多字符类。 Have a look here for other unicode character classes. 看看这里其他的Unicode字符类。

I know this is an old question. 我知道这是一个老问题。

But hope it helps someone out there! 但希望它可以帮助那里的人! you can try this regex: 你可以尝试这个正则表达式:

([\ -\~\ -\ÿ\Ā-\ſ]+)

Basically it should match all the Latin and extended Latin characters, including numbers, feel free to remove the unicode characters as necessary. 基本上它应匹配所有拉丁语和扩展拉丁字符,包括数字,随时删除unicode字符。 I would say that this would be the surest way of getting it right for all your scenarios. 我会说这将是最适合所有场景的方法。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM