简体   繁体   English

用于字母数字,空格和符号的正则表达式,与我需要的不匹配

[英]Regex for Alphanumeric, spaces and symbols, Doesn't match like i need

I want to make a regular expression that matches : 我想制作一个匹配的正则表达式:

-alphanumeric with spaces -these symbols and letters - 带空格的字母数字 - 这些符号和字母

á é í ó ú ñ Ñ ,.( ) ! - + % $

I tried with this, but it didn't match like i need: 我试过这个,但它不符合我的需要:

[\w áéíóúñÑ,.\(\)\!\-\+\%\$]

What's wrong in this regex?? 这个正则表达式有什么问题?

I'm using knockoutjs with knockout validation 我正在使用敲除验证的knockoutjs

.extend({pattern:{message:"No valid.",params:"[\w áéíóúñÑ,.\(\)\!\-\+\%\$]"}});

tested on chrome, firefox, IE10 and Safari browser. 在chrome,firefox,IE10和Safari浏览器上测试过。

You need to escape the special \\ escape character to place an actual \\ in the string. 您需要转义特殊的\\ escape字符以在字符串中放置一个实际的\\ Also, you do not need to escape all these characters, just the ones that have a special meaning within the brackets. 此外,您不需要转义所有这些字符,只需要在括号内具有特殊含义的字符。

Try with: 试试:

"[\\w áéíóúñÑ,.()!\\-+%$]"

this pass ----> "||°°dafsasdf" but this didnt pass the valid ---> "||°°" 这个传球---->“||°°dafsasdf”但这没有通过有效的--->“||°°”

Oh, it's because right now as long as a single character in the string matches the regex, it will pass. 哦,这是因为现在只要字符串中的单个字符与正则表达式匹配,它就会通过。 You have to create a whole pattern match with a defined start and end . 您必须使用定义的开始结束创建整个模式匹配。

"^[\\w áéíóúñÑ,.()!\\-+%$]*$"

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

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