Solved

using Regex in C#

Posted on 2003-12-01
2
234 Views
Last Modified: 2010-04-16
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 MAX 100
.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
thanks,
Xen
0
Comment
Question by:darkxenn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:monkesdb
ID: 9853364
why don't you just test it??

i think it maybe should be

"^\.Data\s*(?<Name>\w*)\s*(?<Value>\w*)"

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

"\.Data\s*(?<Name>\w*)\s*(?<Value>\w*)"

HTH
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 250 total points
ID: 9854014
OK, this one will match it:
^.DATA\s*(?<Name>\w*)\s*(?<Value>\w*)

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: http://www.regexlib.com/RETester.aspx. This is a good place to very quickly test your reg expressions
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question