PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET
Regex: replace first occurence only?
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET
Regex: replace first occurence only?
![]() |
Regex: replace first occurence only? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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. > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

