Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression TO finding text between two phrase 1

Status
Not open for further replies.

xpblueScreenOfDeath

Programmer
Sep 1, 2004
87
I need a regular expression that would find all tags between two phrase or a phrase and a carriage return. For example:
Test1/this is just a test
Test2/abc da da da Test Phase/sssss

I want to be able to get "this is just a test" by matching "Test1/" and a carriage return but I also want to be able to find "abc da da da" by matching "Test2/" and "Test Phase/". What is a regular expression that would work for this.
 
Substring coupled with IndexOf would be a lot easier. I think your request is too vague for a RegEx.


Hope this helps.

[vampire][bat]
 
here is one way
Code:
using System;
using System.Text.RegularExpressions;
class TestRegexMatch
{
	public static void Main(string[] args) 
	{
		string s1 = @"Test1/this is just a test" + System.Environment.NewLine;
		string s2 = @"Test2/abc da da da Test Phase/sssss";
		string pattern = @"(?<=Test[1,2]/)(?<myText>.*?)(?=(Test\s{1}Phase|\n))";
		Console.WriteLine(Regex.Match(s1, pattern).Groups["myText"].ToString()); 
		Console.WriteLine(Regex.Match(s2, pattern).Groups["myText"].ToString()); 
	}
}

Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top