简体   繁体   English

带圆括号的正则表达式

[英]regular expression for square brackets with dot

I am using a regular expression: 我正在使用正则表达式:

^[0-9a-zA-Z/[] ._',()\\n-"]+$ ^ [0-9a-zA-Z / [] ._',()\\ n-“] + $

Its working fine in all the scenario, but I am stuck at a point, when I am trying to enter a square bracket after dot its not working for me. 它在所有情况下都能正常工作,但是当我试图在点后输入方括号对我不起作用时,我陷入了困境。

its working for me when i am trying for

.[

or

.]

expression shows

a. 一种。 dot+square start+space 点+方开始+空格

b. b。 dot+square end+space 点+平方结束+空格

combination when i am trying its not working for me

.[

or

.]

expression shows

a. 一种。 dot+square start 点+方开始

b. b。 dot+square end 点+方结束

You need to escape the special chars. 您需要转义特殊字符。 You probably need something like: 您可能需要类似:

^[0-9a-zA-Z/\[\] \._',\(\)\n\-"]+$

EDIT 编辑

Because you've not escaped your special chars, the regular expression is broken, it's matching some things in the first group, followed by a space, followed by any char (represented by the dot/period), etc. 因为您没有转义特殊字符,所以正则表达式已损坏,它与第一组中的某些内容匹配,然后匹配一个空格,再匹配任何字符(以点/句点表示),等等。

Have you tried the above? 你尝试过以上吗? If you want to comment, it's best to comment in the comments section below my answer (I noticed that you'd tried to edit my answer). 如果您想发表评论,最好在我的答案下方的评论部分发表评论(我注意到您已尝试编辑我的答案)。

EDIT 2 编辑2

If you're trying to match a dot followed by a square bracket, then you want: 如果要匹配点后跟方括号,则需要:

^\.[\[\]]$

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

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