-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regexcapturegroupgs.cs
96 lines (64 loc) · 2.87 KB
/
Regexcapturegroupgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# if false
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.IO;
public static class Programm {
public static void Main(string[] args) {
Console.WriteLine("==== RegexCaptureGroupgs ====\n");
// string pattern = @"(\w+)\s(\1)";
// string input = "He said that that was the the correct answer.";
// foreach (Match match in Regex.Matches(input, pattern, RegexOptions.IgnoreCase))
// Console.WriteLine("Duplicate '{0}' found at positions {1} and {2}.",
// match.Groups[1].Value, match.Groups[1].Index, match.Groups[2].Index);
// string pattern = @"hello\s+(\w+)";
// Console.WriteLine(Regex.Match("hello mofo",@"hello\s(\w+)"));
// foreach (Match match in Regex.Matches("hello mofo hello hehe", pattern)) {
// foreach (var g in match.Groups) {
// Console.WriteLine($"match value: {match.Value}.. group: {g.ToString()}");
// }
// }
// for (var i = 0; i < matches.Count; i++) {
// Console.WriteLine($"match {i}");
// for (var j = 0; j < matches[i].Groups.Count; j++) {
// Console.WriteLine($"group {j} {matches[i].Groups[j].ToString()}");
// }
// }
// var str = "mee ld";
// foreach (Match match in Regex.Matches(str,@"([\w\s]+)")) {
// foreach (var g in match.Groups) {
// Console.WriteLine(g);
// }
// }
// return;
var input = File.ReadAllLines("/home/benj/idlegame/IdleGame/Assets/Editor/AssetTools/difftoolspecfile.txt");
var programName = "";
var _args = "";
foreach (var line in File.ReadAllLines("/home/benj/repos/unity-sample/UnitySample/Assets/Editor/difftoolspecfile")) {
if (line.StartsWith("#")) continue;
var matches = Regex.Matches(line,@"^\* use ""([\w\s]+)""");
if (matches.Count == 1) {
programName = matches[0].Groups[1].ToString();
_args = line.Substring(matches[0].Groups[0].Length);
Console.WriteLine(programName);
Console.WriteLine("args:");
Console.WriteLine(line.Substring(matches[0].Groups[0].Length + 1));
break;
}
}
if (String.IsNullOrEmpty(programName)) {
Console.WriteLine("Error diff tool file.");
}
// if windows
var first = programName.Replace("%programs%",@"C:\Program Files");
// Console.WriteLine(first);
var second = programName.Replace("%programs%",@"C:\Program Files (x86)");
// Console.WriteLine(second);
// substring
// Console.WriteLine(str.Substring(programName.Length - 1));
}
}
# endif