Solved

Regular Expression

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now