PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Regex: replace first occurence only?

Reply

Regex: replace first occurence only?

 
Thread Tools Rate Thread
Old 02-04-2006, 11:53 PM   #1
Alexey Smirnov
Guest
 
Posts: n/a
Default Regex: replace first occurence only?


Regex.Replace("BUILDING IN PARIS, IN LONDON" ,"\bIN\b","???");
returns "BUILDING ??? PARIS, ??? LONDON"

I need to replace the first match only, to have "BUILDING ??? PARIS, IN
LONDON"

How can I do that?

Thanks.


  Reply With Quote
Old 03-04-2006, 02:27 AM   #2
Cerebrus
Guest
 
Posts: n/a
Default Re: Regex: replace first occurence only?

Hi Alexey,

Many of the overloads of the Regex.Replace method allow you to choose a
number to specify the number of occurrences of a match that you would
like to replace. Check them out and choose the one that is most
appropriate for you.

Possibly, you could use this one : Regex.Replace("input",
"replacement", count)...

Regards,

Cerebrus.

  Reply With Quote
Old 12-04-2006, 01:13 AM   #3
Alexey Smirnov
Guest
 
Posts: n/a
Default Re: Regex: replace first occurence only?

thank you, I found how to do that (forgot to check documentation :-)


"Cerebrus" <zorg007@sify.com> wrote in message
news:1144024032.900482.123200@e56g2000cwe.googlegroups.com...
> Hi Alexey,
>
> Many of the overloads of the Regex.Replace method allow you to choose a
> number to specify the number of occurrences of a match that you would
> like to replace. Check them out and choose the one that is most
> appropriate for you.
>
> Possibly, you could use this one : Regex.Replace("input",
> "replacement", count)...
>
> Regards,
>
> Cerebrus.
>



  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off