Matching separate regions
-
Hi, I'm using Notepad++ to do some Regex replacements and have come up against a problem I can't solve. I'm looking to match a region between two fixed strings inclusive (called and for the sake of example). The problem I have is these strings appear multiple times throughout, but I want to match EACH instance, rather than one match from the very first to the last . They may or may not be over many lines. For example: ...text body... ...other text... ...text body... ...other text... ...text body... I need my Regex to make 3 separate matches, rather than 1 big match which includes all the ..other text... which I need to be left intact. The above needs to work irrespective of whether the and are on the same line or many lines apart. Thanks in advance.
-
Hi, I'm using Notepad++ to do some Regex replacements and have come up against a problem I can't solve. I'm looking to match a region between two fixed strings inclusive (called and for the sake of example). The problem I have is these strings appear multiple times throughout, but I want to match EACH instance, rather than one match from the very first to the last . They may or may not be over many lines. For example: ...text body... ...other text... ...text body... ...other text... ...text body... I need my Regex to make 3 separate matches, rather than 1 big match which includes all the ..other text... which I need to be left intact. The above needs to work irrespective of whether the and are on the same line or many lines apart. Thanks in advance.
Try:
public static Regex regex = new Regex(
"\\.*?\\",
RegexOptions.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
...
MatchCollection ms = regex.Matches(InputText);Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Try:
public static Regex regex = new Regex(
"\\.*?\\",
RegexOptions.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
...
MatchCollection ms = regex.Matches(InputText);Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
Thanks, that's led me to the correct solution for all eventualities :thumbsup:
-
Thanks, that's led me to the correct solution for all eventualities :thumbsup:
You're welcome!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!