Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

replacement expression

0 views
Skip to first unread message

nospam Paal @everywheredotcom Jon Paal [MSMD]

unread,
May 8, 2008, 2:06:06 PM5/8/08
to
need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove parentheses
...

str.replace(/\([\w\s]*\)/gi, "");

any suggestions ?

apatheticagnostic

unread,
May 8, 2008, 2:40:40 PM5/8/08
to
On May 8, 2:06 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot

Looks like it should, although you won't be stripping digits. What's
the issue?

nospam Paal @everywheredotcom Jon Paal [MSMD]

unread,
May 8, 2008, 3:23:07 PM5/8/08
to

"apatheticagnostic" <apatheti...@gmail.com> wrote in message
news:3fc20dfe-e95f-4272...@m36g2000hse.googlegroups.com...

It's not working...

sample string is :

"Electronic media (DVDs, CDs), Paper (books, photos), Textiles (clothes, linens), Furniture"

should return:

"Electronic media, Paper, Textiles, Furniture"


apatheticagnostic

unread,
May 8, 2008, 7:33:46 PM5/8/08
to
On May 8, 3:23 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
com> wrote:
> "apatheticagnostic" <apatheticagnos...@gmail.com> wrote in message

It's the commas in the parens.

str.replace(/\([^\)]*\)/gi, '');

Doc O'Leary

unread,
May 9, 2008, 12:40:04 PM5/9/08
to
In article <ZIWdnV4pe96T3L7VnZ2dnUVZ_jydnZ2d@palinacquisition>,

"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot com> wrote:

\([^)]*\)

--
My personal UDP list: 127.0.0.1, 4ax.com, buzzardnews.com, googlegroups.com,
heapnode.com, localhost, ntli.net, teranews.com, vif.com, x-privat.org

Dr J R Stockton

unread,
May 9, 2008, 6:09:52 AM5/9/08
to
In comp.lang.javascript message <3fc20dfe-e95f-4272-b5f1-4108644186b5@m3
6g2000hse.googlegroups.com>, Thu, 8 May 2008 11:40:40, apatheticagnostic
<apatheti...@gmail.com> posted:

Posting correct untested answers requires real intelligence; one rarely
finds that in the witterings of anonymous gmail users.


The test string subsequently provided contains parenthesised commas; the
RegExp does not accommodate that.

This works on the test data : str.replace(/\([^)]*\)/g, "");
-> Electronic media , Paper , Textiles , Furniture

And str.replace(/\s*\([^)]*\)/g, "");
-> Electronic media, Paper, Textiles, Furniture

--
(c) John Stockton, nr London UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.

0 new messages