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
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
"[A-Za-z0-9 ]+"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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.
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.