Modify an existing regex to match '.' aswell
I'm currently using this regex ^[A-Z0-9 _]*$ to accept letters, numbers, spaces and underscores. I need to modify it t开发者_如何学Co allow . 
Assuming you want to allow period (.), just add it to the character class. 
^[A-Z0-9 _.]*$
A period inside a character class is treated literally which means there is not need to escape it. But escaping it as:
^[A-Z0-9 _\.]*$
is also correct and many use it. Check it out.
The following regex matches \ and . aswell.
^[A-Z0-9 _\\.]*$
To allow period? add \. inside the []
Edit: TIL inside square brackets periods don't need to be escaped in regex.
So just a ., no \ 
 加载中,请稍侯......
      
精彩评论