tags:

views:

70

answers:

2

What I'd like to do remove the part of a string that is contained in brackets.

So for example be able to go from "Hello (World)" to "Hello".

I am using var input2 = '\([0-9a-zA-z]*\)'; as my expression statement, and using regular expressions to match this pattern.

Can someone tell me what I'm going wrong? I must be escaping the "(" and ")" incorrectly.

+4  A: 

A-z should be A-Z.

If you want to be safe with those backslashes, escape the backslashes so you get \\( and \\) respectively, although I see nothing wrong with the backslashes.

BoltClock
Don;t think that [A-z] will stop it mathcing. That matches A-Z [\]^_` and a-z
justintime
@justintime: I don't think he meant that as a solution. But `[A-z]` is obviously a typo, and we would be remiss if we didn't point it out.
Alan Moore
Yes, that was a typo - thanks for catching it.
nazbot
OK - fair point
justintime
A: 

Is this JavaScript? If so, you either need to escape the backslashes like @BoltClock said, or use a regex literal:

var input2 = /\([0-9a-zA-Z]*\)/;
Alan Moore
Would the downvoter care to explain why? I can't correct my mistake if I don't know what it is. :D
Alan Moore