Re: Regular Expression Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The best way I can think of it is using the following:

(?i)(?:<a[^>]*href="?){1}(?<url>[^\s>"]*)

The first expression is a mode modifier, indicating that the regex is
case-insensitive. I prefer to use these rather than setting options. The
second part is a non-capturing group that defines the beginning of a link
tag, and it specifies exactly one time. Because an HTML tag may or may not
use quotes in the attribute value, the quote prior to the URL is optional (0
or 1 time). After that there is a single group named "url" that contains the
URL you're looking for. It is defined as any number of any character that is
NOT a space, right angle bracket, or a quote. You replace the group using
the Regex.Replace override that takes a MatchEvaluator delegate.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Matthias S." <matthias&AtSign&emvoid$dot$com> wrote in message
news:Oj5wl4QVHHA.5100@xxxxxxxxxxxxxxxxxxxxxxx
Hi there,

I'm trying to build a regular expression which will do a replace for me.
I'm
getting grey hair on this one:

here is my input string:
<a href="http://test.com/fun.jpg"; target="_blank">my fun pic</a>

I'd like to turn this into the following:
[url=my fun pic]http://test.com/fun.jpg[/url]

Can somebody help me building such a regular expression? Any help is
greatly
appreceated. Thanks in advance!

Matthias




.



Relevant Pages

  • Re: R.I.P> The Autophiles BOFH.
    ... >> I have a great deal of fun with fundie Xtians when they quote "THE ... >> appendix to The Bible, not The Bible itself; I'm Jewish, and that's ...
    (alt.sysadmin.recovery)
  • Re: New Doc
    ... treatment with Schedule II & III Opiates need to purchase them from a websites at a significant premium price when they can get them via prescription at a traditional Brick & Mortar pharmacy. ... everyone who really wants it can get proper treatment for their pain. ... at a price significantly above market via the web from <quote: ... That reason is if you are a recreational abuser <quote: having fun> and aren't able to scam a real life Doc in person. ...
    (alt.support.chronic-pain)
  • Re: Crossware - ColdFire
    ... posting to newsgroups these days ... ... Attempting to communicate a bit of fun to some people requires a bit of ... To quote your quote more fully ... ... grammatical structure requires the use of the verb tense "missed". ...
    (comp.arch.embedded)
  • Re: R.I.P> The Autophiles BOFH.
    ... >> I have a great deal of fun with fundie Xtians when they quote "THE ... >> appendix to The Bible, not The Bible itself; I'm Jewish, and that's ...
    (alt.sysadmin.recovery)
  • Re: another preg_split problem
    ... If it's a quote, look for the first non-escaped quote, and chop after it. ... > I've got a CSV file that I want to split using preg_split. ... > somebody has an idea how I can make up my regular expression so it will ...
    (alt.php)