using Regex in C#

Hey guys...

Tryin to use Regex for the first time to write an interpreter for a really simple language, but i really dont know what i am doing with Regex, and am probably just wasting my time trying to do it by myself, so i figured yall could help..

lets say that i am trying to match the following phrase

.DATA(Keyword) MAX(Variable Name) 100(Value)

Regex PD = new Regex( "^.Data\s*(?<Name>\w*)\s*(?<Value>\w*)", RegexOptions.Compiled );

Match pMatch = PD.Match( ".DATA MAX 000h" );

if( pMatch.Success )
   string strName = PD.Groups[ "Name" ].Value;
   string strValue = PD.Groups[ "Value" ].Value;

will this strip every possible .DATA VAR_NAME VALUE string out there, no matter how many spaces are between the words, or tab characters, or comments (using #) after the value?

basically, i need that to be able to match

.DATA          MAX        100
.DATA MAX 100 #comment here

need help
Who is Participating?
TheAvengerConnect With a Mentor Commented:
OK, this one will match it:

but it will not read any more characters after that, neither will search for end of text. It is important to match the case (DATA instead of Data).

Have a look here: This is a good place to very quickly test your reg expressions
why don't you just test it??

i think it maybe should be


. is an 'any character' wildcard, if your string holds more than one of these  .DATA VAR_NAME VALUE  sets then just remover the ^


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.