Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Regular Expression

I have a dynamic url string which I am trying to convert the string to html bold string character.

For example
$url='http://www.experts-exchange.com'
$url=~s/(http:)/<b>$1<\/b>/ig;

Therefore $url='<b>http:</b>

This is not the output that I want. How do you change the regular expression to get my desired out that is
$url='<b>http://www.experts-exchange.com</b>'

Pls bare in mind that the url is dynamic.
0
ghgan
Asked:
ghgan
1 Solution
 
andreifCommented:
If there is only URL in the string, use

$url='http://www.experts-exchange.com'
$url=~s/(http:)(.*)$/<b>$1$2<\/b>/ig;

If there is another text, you should define the end of url:

$url='http://www.experts-exchange.com something else'
$url=~s/(http:)(.*?)\s/<b>$1$2<\/b>/ig;

or limit characters that can be included into the url (not sure that I remember all chars, check this :)

$url=~s/(http:)([\w\-\&\?\d\.\/\\]+)/<b>$1$2<\/b>/ig;
0
 
bigbedCommented:
$url = "<b>$url</b>";

Is that what you meant?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now