Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Set arr yourself.
- ///Returns a List<List<string>>
- ///If you have "A || B", it will return
- /// { {A, B} }
- ///If you have "A , B" , it will return
- /// { {A}, {B} }
- ///If you have A || B, C, D || E, it will return
- /// { {A, B}, {C}, {D, E} }
- List<List<string>> regex2()
- {
- string pattern = @"(?<Relationship>(,)|(\|\|)|)(?<Name>\w+)(\[(?<Class>\w+)\]|)";
- string[] arr =
- {
- "Statis_Flange[Class_1]||Objectivity_Anchor[Class_1]",
- "Targeting_Jammer",
- "Targeting_Jammer,Targeting_Jammer"
- };
- List<List<Comp>> list = new List<List<Comp>>() ;
- foreach(string s in arr)
- {
- bool isOptional;
- foreach(Match m in Regex.Matches(s, pattern))
- {
- string cClass, cName, cRelationship;
- cName = m.Groups["Name"] .Value;
- cClass = m.Groups["Class"] .Value;
- cRelationship = m.Groups["Relationship"].Value;
- Debug.Log("Name: "+cName+" Class:"+cClass+" Relationship:"+cRelationship);
- Comp c = new Comp{ cName = cName, cClass = cClass } ;
- if(cRelationship == "||")
- {
- list[list.Count-1].Add( c );
- }
- else //"," or ""
- {
- list.Add(new List<Comp>{ c });
- }
- }
- }
- return list;
- }
- class Comp
- {
- public string cName;
- public string cClass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement