Link to home
Start Free TrialLog in
Avatar of MaritimeSource
MaritimeSource

asked on

regular expression - retain alpha numeric and spaces

Hi,

I'm a dummy when it comes to regex... I need one that retains characters, numbers and spaces.

It should take performance into consideration.

Thanks
Avatar of brettmjohnson
brettmjohnson
Flag of United States of America image

"[A-Za-z0-9 ]+"
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MaritimeSource
MaritimeSource

ASKER

Objects,

Are you saying that this:
s = s.replaceAll("[^\w ]", "");

is the same as this:
s = s.replaceAll("[^A-Za-z0-9 ]", "");

except the former retains underscore as well?

I was informed that String.replaceAll is not as fast as using the java.util.regex library. Is this true?
> except the former retains underscore as well?

correct \w matches a-zA-Z_0-9

> I was informed that String.replaceAll is not as fast as using the java.util.regex library. Is this true?

doubt it, replaceAll() uses regex library.