Solved

Regular Expression

Posted on 2001-08-01
2
174 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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