简体   繁体   中英

regular expression for square brackets with dot

I am using a regular expression:

^[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. dot+square end+space

combination when i am trying its not working for me

.[

or

.]

expression shows

a. dot+square start

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

If you're trying to match a dot followed by a square bracket, then you want:

^\.[\[\]]$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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