Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expression

Posted on 2001-08-01
2
Medium Priority
?
189 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 40 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
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

670 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