Hi Monks;
I am having a problem trying to format a url. The last part of my url will be names with spaces between them. Example, if the last name of my url looks like something like:
Inn House Company and Services, my url will end like this "http://my.test.com?infor=info2&company_name=Inn" everything after the first word because is followed by space will not be part of the url. What I am trying to do is to replace all the spaces coming from a variable $company_name per example, that has spaces in it to %20, but some how I am still not able to make one that would take any name format.
I am wondering is there is a better way to say:
I any company name has any spaces between them replace the spaces with %20, here is my regular expression, but as you can see it is not efficient as it should be.
if ($company_name=~s/(\w\&\w|\w*)(\s?)(\w*)(\s?)(\w*|\w\.)(\s?)(.*)$/$ +1%20$3%20$5%20$7/) .....

And I do have names like:
Soft, Inc. LTD
Y.O.U Co. and Services
General Help Company

It can also make the reg. exp. even more difficulty to match.
Thanks for the help.

20040409 Edit by BazB: Changed title from 'Regular Expression'


In reply to Encoding a URL with regular expressions? by Anonymous Monk

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.