http://www.perlmonks.org?node_id=157804

Superman has asked for the wisdom of the Perl Monks concerning the following question: (regular expressions)

i have a scalar as follows
$journal = STRUCTURE (LONDON)
when i query this in cgi, it is done so as
STRUCTURE+(LONDON)
this gives the + in the middle to complete the URL.
However in order to query the URL PROPERLY i need for my string to read
$journal = STRUCTURE LONDON
so that the CGI query is STRUCTURE+LONDON.
how can i write a regex that will remove these brackets from the string???
$journal = ~ s/ (help remove brackets) //g;
thanks in advance

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: how do i replace brackets in a regex?
by particle (Vicar) on Apr 09, 2002 at 18:11 UTC
    $journal =~ tr/)(//d;
Re: how do i replace brackets in a regex?
by Schuk (Pilgrim) on Apr 18, 2002 at 14:37 UTC
    or

    $journal =~ s/(\)|\()//g;

    "s" for replace
    "\)" and "\(" for escaping the brackets
    "|" for or
    and the whole thing in "(..)" because you want to replace it with nothing "//"
    "g" finally stands for global -> replacement doesnt stop when you hit the first bracket.
Re: how do i replace brackets in a regex?
by I0 (Priest) on Apr 20, 2002 at 08:03 UTC
    or $journal =~ s/[()]//g;