Ruby Regex to match nodes in Puppet file
-
Sunday, March 04, 2012 1:39 AM
Hi everyone
This is my first post here, I am new to regex and I am struggling with writing a regex in puppet's nodes file, the regex should do the following:
I have two types of systems:
1) [a-z]qa-phppl
2) [a-z]qa-phppl-worker, I want to write two regex which parses these two system type.
(by[a-z] I mean that first letter can be any of the alphabets) The name format always remains the same except for the first letter which can be any alphabet.
it would be like:
regex for 1)
do something;
regex for 2)
do something else;
Can any one please help,
Thanks
All Replies
-
Sunday, March 04, 2012 3:01 AM
Please guys help me, am new to regex and have posted on this forum with great expectations.
Thanks
-
Monday, March 05, 2012 9:54 AMModerator
I just wrote a code snippet for your reference:
string str = @"qwqa-phppl-worker, aqa-phppl-workerasd, 1qa-phppl-workerasd . asdqa-phppl asd.231asdqa-phppl asd "; Regex reg02 = new Regex(@"[a-z](qa-phppl)(-worker)[a-z]*");// qa-phppl-worker Regex reg01 = new Regex(@"[a-z](qa-phppl)");//qa-phppl MatchCollection ma = reg02.Matches(str); foreach (Match mti in ma) { Console.WriteLine(mti.Value);//print with -worker Match ma2 = reg01.Match(mti.Value); Console.WriteLine(ma2.Value);//print qa-phppl if matched. }And the followings materials for your reference too:
http://msdn.microsoft.com/en-us/library/6f7hht7k.aspxhttp://www.w3schools.com/jsref/jsref_regexp_g.asp
http://msdn.microsoft.com/en-us/library/3zy662f6.aspx
Hope it helps.
Best Regards,
Rocky Yue[MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Lie YouModerator Friday, March 09, 2012 2:32 AM

