Solved

Regular Expression

Posted on 2001-08-01
2
184 Views
Last Modified: 2010-03-05
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
Comment
Question by:ghgan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
andreif earned 10 total points
ID: 6339649
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
 
LVL 3

Expert Comment

by:bigbed
ID: 6341085
$url = "<b>$url</b>";

Is that what you meant?
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question