April 15th, 2010, 12:10 AM
I have text which can look like any of these:
Perhaps there is a better method then .replace for this? Any help would be greatly appreciated.
April 15th, 2010, 12:16 AM
I guess I could use match
Although that regex returns null
txt = string.match('/\(.*?\)/');
April 17th, 2010, 08:47 AM
That code snippet isn't working as you expect because the forward slashes are used literally because it's a string, so it's silently being converted to a regexp object.
I might do it like this: (the join, replace, and split method calls are to remove the parentheses.)
txt = string.match(/\([^\(\)]+\)/g).join('').replace(/\(|\)$/g,'').split(/\)/);