Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^a-zA-Z0-9 excluding spaces?

Tags:

regex

spaces

I am trying to find everything in a paragraph that is not abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 and not space / /gi

/[^a-zA-Z0-9]|[^ ]/gi

the above doesn't work!

like image 422
Ben Muircroft Avatar asked Mar 08 '12 22:03

Ben Muircroft


People also ask

How do you say no space in regex?

Need to use a regex to match - "no character or one character" or "zero or one space". If so, you may use the following syntax to match similar patterns: [ ]{0,1} - match no space or 1 space.

What does a zA Z0 9 ]+ mean?

The bracketed characters [a-zA-Z0-9] mean that any letter (regardless of case) or digit will match. The * (asterisk) following the brackets indicates that the bracketed characters occur 0 or more times.

What is ?: In regex?

It indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s) , even though it's enclosed by () it won't appear in the list of matches, only (\w+) will.


1 Answers

If you only want to exclude spaces use:

[^ ]*

Test the regex here if you want.

like image 185
xdevs23 Avatar answered Sep 22 '22 11:09

xdevs23