JM wrote:
Quote:
Given a string like: "Boston. MA. Holidays" I need to define the regular
expression to find each dot, the previous word and the word after. That is i
want to obtain:
>
first match: "Boston" "." "MA"
second match: "MA" "." "Holidays"
>
The problem is that if I use somthing like: ([^\s\.]+)(\.)(\s*[^\s\.]+) I
"cosume" MA in the first macth so I do not have a second match. That is I
obtained:
>
first match: "Boston" "." "MA"
and no more matches, since MA is consumed in the previous match.
One solution is to use the Match overload that takes a search start
offset - Regex.Match (String, Int32) - for your second (and
subsequent) matches. If your second Match operation starts at the "MA"
substring's offset, it won't matter that "MA" was consumed by the
first Match.
--
Be the first to review my new book!
..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.