You left out a few important details (and code tags). What was the original string, and the actual regex that was supposed to apply for extracting $keyword?

An empty result means that your initial regex match is not working as expected, so if you showed us the original string and the initial regex, we'd be able to tell you why it failed.

If your initial regex only had one set of parens, then there is no $2 that results from the match -- you need to use $1 instead. Apart from that, if a string contains "+", then your statement  s/\+/\s/g will replace each "+" with a literal "s" -- things like "\s, \d, \b" don't work in the right-hand (replacement) side like they do in the left-hand (match) side (but things like "\n, \t, \r" do).

You want to say  s/\+/ /g instead.

P.S.: learn about using code tags by looking at Writeup Formatting Tips. You'll see a link to that page every time you preview a new post. Use it.


In reply to Re: substitute with space by graff
in thread substitute with space by vitaly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.