views:

20

answers:

1

I have a string of characters and want to isolate 2 characters.

Isolate a or b from string:

"a48y jvu5agbl=dbz'bk;ahc"

Should get something like this:

aabbba

This regex gets me the correct result and whatever's left. How do I chop off the end?

str.replace(/.*?(b|a)/g,"$1");

Thanks. Any other way to isolate the characters is great too.

Thanks.

+3  A: 

You might have an easier time with [^...] to grab everything but and remove it:

str.replace(/[^ab]+/g, '');
Jonathan Lonowski