PC Review


Reply
Thread Tools Rate Thread

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

 
 
maziar.aflatoun@gmail.com
Guest
Posts: n/a
 
      22nd Apr 2009
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.

 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      22nd Apr 2009
Hello (E-Mail Removed),

Hello (E-Mail Removed),

Answered in another newsgroup.


> 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>>
> <IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="beta/">beta/</
>

A>> 10-Mar-2009 20:47 -
A>>
> <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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Regular expression to find all instance and add a prefix maziar.aflatoun@gmail.com Microsoft Dot NET 1 22nd Apr 2009 11:57 PM
C# Regular expression to find all instance and add a prefix maziar.aflatoun@gmail.com Microsoft ASP .NET 2 22nd Apr 2009 11:56 PM
Hi Just want to find out if regular expression is possible. Vinay Bhushan Microsoft C# .NET 1 29th Apr 2008 05:41 PM
Regular Expression Regex/Match fails if regular expression returns a null tdmailbox@yahoo.com Microsoft C# .NET 1 31st May 2005 02:19 AM
Customizing Regular Expression Editor for Regular Expression Validator Control Jason Timmerman Microsoft Dot NET Framework 0 27th Oct 2003 08:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:29 PM.