6

I understand that given a string str

str.replace(/\s/g,'');

will remove all spaces in a string.

How can I remove all characters that are not lower case letters from the string?

1 Answer 1

19

You could:

str.replace( /[^a-z]/g, '' );
7
  • would str.match(/[^A-Z]/g, ''); do the same? i'm having a heck of a time with regex in JS =/
    – aug2uag
    Mar 22, 2013 at 20:01
  • @Lucas The OP is looking to remove all uppercase. You're removing all lowercase
    – Ian
    Mar 22, 2013 at 20:02
  • @Lucas Oops, sorry, you have the ^
    – Ian
    Mar 22, 2013 at 20:03
  • 1
    Thanks! This works just like I wanted it. I will have to wait 10 min before I can accept your answer.
    – Thomas
    Mar 22, 2013 at 20:03
  • @Lucas: This is the answer, but I can't accept your answer. I have to wait 8 min.
    – Thomas
    Mar 22, 2013 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.