帮助正则表达式。 [英] Help in regular expression.

查看:101
本文介绍了帮助正则表达式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我为一个电子邮件字段设置了以下regEx模式,我需要允许连字符(' - ')。这意味着电子邮件字段应允许 - 以及所有其他限制。以下是已定义的正则表达式:



 / ^((([az] | \d | [_] | [\ u00A0 -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])+(\([AZ] |。\d | [_] | [\\\ -\\\퟿\\\豈- \\\﷏\\\ﷰ-\\\￯])+)*)|((\x22)((((\x20 | \x09)*(\x0d\x0a))?(\x20 | \x09)+)(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f] |?\x21 | [\x23-\x5b] | [\x5d-\x7e] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(\\([\x01-\x09\\ \\x0b\x0c\x0d-\x7f] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯]))))*(((\x20 | \\ \\x09)*(\x0d\x0a))(\x20 |?\x09)+)(\x22)))@((([AZ] |?\d | [\\\ - \\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(([AZ] | \d | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\ \￯])([AZ] | \d |  -  |。\ | _ |〜| [\u00A 0-\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])*([AZ] | \d | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ- \\\￯])))\)+(([AZ] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(([AZ] | [ \\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])([AZ] | \d |  -  |。\ | _ |〜| [\\\ -\\\퟿ \\\豈-\\\﷏\\\ﷰ-\\\￯])*([AZ] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])))\ 。$ $ / i 





我的尝试:



因为这太复杂了,我无法理解并解决这个问题。我试了很多东西,把连字符放在很多地方,但是没有成功。你能帮忙吗?

解决方案

/ i





什么我试过了:



因为这太复杂了,我无法理解并解决这个问题。我试了很多东西,把连字符放在很多地方,但是没有成功。你可以帮帮忙吗?


它并不复杂,只是讨厌。

要么回到你从那里得到的地方 - 因为如果你写了它你就会知道它是如何工作的 - 或者学习正则表达式并自己修改它。我们不能为你做这件事,因为我们不知道应该在哪里允许' - '而它不在哪里:部分已经明确允许连字符。

这可能会有所帮助:< a href =http://www.ultrapico.com/Expresso.htm> Expresso [ ^ ] - 它是免费的,它检查并生成正则表达式。


我修改了正则表达式模式



 ^(([[ -  az] | \d | [_] | [\\\00A0-\DD7FF \ uF900-\ uFDCF \ uFDF0-\\ \￯])+(\([AZ] |。\d | [_] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])+)*) |((\x22)((((\x20 | \x09)*(\x0d\x0a))(\x20 |?\x09)+)(([\x01-\\ \\x08\x0b\x0c\x0e-\x1f\x7f] | \x21 | [\x23-\x5b] | [\x5d-\x7e] | [\\\ -\\ \퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(\\([\x01- \\x09\x0b\x0c\x0d-\x7f] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯]))))*(((\ X20 | \x09)*(\x0d\x0a))(\x20 |?\x09)+)(\x22)))@((([AZ] |?\d | [\\ \ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(([AZ] | \d | [\\\ -\\\퟿\\\豈-\\\﷏\ uFDF0-\\\￯])([AZ] | \d |  -  |。\ | _ |〜| [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯]) *([AZ] | \d | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])))\)+(([AZ] |。[\ u00A0-\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])|(([AZ] | [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯ ])([AZ] | \d |  -  |。\ | _ |〜| [\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])*([AZ] |。?[\\\ -\\\퟿\\\豈-\\\﷏\\\ﷰ-\\\￯])))\ 

Hi,

I have the following regEx pattern placed for one Email field, I need to allow hyphen ('-') in the same. That means that the email field should allow '-' along with all the other restrictions. Following is the regex already defined:

/^((([a-z]|\d|[_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i



What I have tried:

As this is too complex, i couldn't comprehend and fix this. I tried a lot of stuff, putting hyphen at a lot of places, however didnt succeed. Can you help?

解决方案

/i



What I have tried:

As this is too complex, i couldn't comprehend and fix this. I tried a lot of stuff, putting hyphen at a lot of places, however didnt succeed. Can you help?


It's not complex, it's just nasty.
Either go back to where you got that from - because if you had written it you'd know how it worked - or learn regexes and modify it yourself. We can't do it for you because we have no idea where it is supposed to allow '-' and where it isn't: parts of that already permit hyphens explicitly.
This may help: Expresso[^] - it's free, and it examines and generates Regular expressions.


I modified regex pattern

^((([-a-z]|\d|[_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?


这篇关于帮助正则表达式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆