Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - C# Regular expression to find all instance and add a prefix

Reply
 
Old 04-22-2009   #1 (permalink)
maziar.aflatoun


 
 

C# Regular expression to find all instance and add a prefix

Hi,

My knowledge of RE is really rusty now. Can someone please help me out
with this problem,

I make a request to our other server that's running php and I grab the
content of the directory in html format. Next I
want to search for all the instances of SRC="???"

<IMG SRC="/icons/back.gif" ALT="[DIR]"> <A HREF="/updates/">Parent
Directory</A> 06-Apr-2009 01:06 -
<IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="ad/">ad/</
A> 06-Apr-2009 01:12 -
<IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="beta/">beta/</
A> 10-Mar-2009 20:47 -
<IMG SRC="/icons/unknown.gif" ALT="[ ]"> <A
HREF="something">something..&gt;</A> 10-Apr-2008 00:13 94.9M

and replace it with http://www.ourdomain.com/??? so SRC="/icons/
back.gif" would become SRC="http://www.ourdomain.com/icons/back.gif".
I need this for even known image names in the future.

I have this so far

string regex = "src=\"([^\"]+)"; // which pulls out /icons/image.gif
page
Regex r = new Regex(regex, RegexOptions.IgnoreCase);

return r.Replace(html, "$1").Replace(?????????) // now how to do I
apply the prefix part?

Can you please help me out or show me more simple way?

Thanks
M.

My System SpecsSystem Spec
Old 04-22-2009   #2 (permalink)
Jesse Houwing


 
 

Re: C# Regular expression to find all instance and add a prefix

Hello maziar.aflatoun@xxxxxx,

Answered in another newsgroup.


Quote:

> Hi,
>
> My knowledge of RE is really rusty now. Can someone please help me out
> with this problem,
>
> I make a request to our other server that's running php and I grab the
> content of the directory in html format. Next I
> want to search for all the instances of SRC="???"
> <IMG SRC="/icons/back.gif" ALT="[DIR]"> <A HREF="/updates/">Parent
> Directory</A> 06-Apr-2009 01:06 -
> <IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="ad/">ad/</
A>> 06-Apr-2009 01:12 -
A>>
Quote:

> <IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="beta/">beta/</
>
A>> 10-Mar-2009 20:47 -
A>>
Quote:

> <IMG SRC="/icons/unknown.gif" ALT="[ ]"> <A
> HREF="something">something..&gt;</A> 10-Apr-2008 00:13 94.9M
> and replace it with http://www.ourdomain.com/??? so SRC="/icons/
> back.gif" would become SRC="http://www.ourdomain.com/icons/back.gif".
> I need this for even known image names in the future.
>
> I have this so far
>
> string regex = "src=\"([^\"]+)"; // which pulls out /icons/image.gif
> page
> Regex r = new Regex(regex, RegexOptions.IgnoreCase);
> return r.Replace(html, "$1").Replace(?????????) // now how to do I
> apply the prefix part?
>
> Can you please help me out or show me more simple way?
>
> Thanks
> M.
--
Jesse Houwing
jesse.houwing at sogeti.nl


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Regular Expression help C# .NET General
Regular Expression for ../ .NET General
Help with a regular expression VB Script
regular expression help VB Script
Regular expression notes PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46