Raul Marquez
Raul Marquez

Reputation: 1116

Allow all characters and spaces restrictions regex javasctipt

I found this regex which acomplishes the following:

^(\w+\s)*(\w+$)

But I also need to allow any character and currently it only accepts alphanumeric values.

How do I write this?

Upvotes: 0

Views: 47

Answers (1)

ASDFGerte
ASDFGerte

Reputation: 5193

Replace \w (which matches [a-zA-Z0-9_]) with \S (not a whitespace character, as mentioned in the comments. Should be equivalent to [^\s] but if there is a shorthand, better use it), making ^(\S+\s)*(\S+$).

Note that this matches everything that is not matched by \s, also any weird unicode symbols or the likes.

This is a token answer as there seem to be no answers after my comment and OP noted that marking as resolved cannot be done on comments.

Upvotes: 1

Related Questions