47
Views
6
Comments
Solved
unrecognized escape sequence Regex error.
Application Type
Reactive

Hi All,

I'm using Regex Search in my application and I want to allow users to add ' _ ' (Underscore ) also with their Names.

I'm able to use ' -  &  , ' but if I'm using ' _ ' then it is showing me this error.


Kindly help in this.

2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

Hi Saransh,

Can you try the below-mentioned Regex pattern for your use case?

"^[\w \-\&\,]+$"

Note: \w is equivalent to [A-Za-z0-9_] 

See this sample screen: RegexTask

I hope this helps you!


Kind regards,

Benjith Sam

UserImage.jpg
Saransh

ok let me try this one


2021-03-18 21-03-15
Benjith Sam
 
MVP

Hi Saransh,

The underscore character is already included in the \w i.e. \w (word character) matches any single letter, number or underscore (same as [a-zA-Z0-9_] ) 


Kind regards,

Benjith Sam

UserImage.jpg
Saransh

It is working man how did you find it? What was your strategy to find this?

2021-03-18 21-03-15
Benjith Sam
 
MVP

No as such unique strategy to mention. I just referred to multiple related posts (Google search) and then trailed and tested multiple patterns to draft the final pattern ;)

Glad that it helped you :)


Kind regards,

Benjith Sam 

UserImage.jpg
Wendy Tromp

Still, it's pretty silly not to be able to escape an underscore.....

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.