-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionExtractString.cs
More file actions
38 lines (30 loc) · 1.05 KB
/
FunctionExtractString.cs
File metadata and controls
38 lines (30 loc) · 1.05 KB
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
using System.Text.RegularExpressions;
namespace CopyLine
{
class ExtractString
{
// trim head and end space (' ') and tab (\t)
static char[] charsToTrim = {' ', '\t'};
// ignore tag
static string pattern1 = @"^(#+|\(begin\)|\(end\))";
// remove leading bullet point symbol
static string pattern2 = @"^(\(?[A-Za-z0-9]+[\)\.][ \t]+|[-\+\*][ \t]+)?(?<content>.+)";
// remove last symbols
static string pattern3 = "(#{2,}|[○×]).*";
public static string GetExtractString(string str)
{
if (str == string.Empty)
{
return string.Empty;
}
if (Regex.IsMatch(str, pattern1)) {
return string.Empty;
}
string res1 = str.Trim(charsToTrim);
string res2 = Regex.Match(res1, pattern2).Groups["content"].Value;
string res3 = Regex.Replace(res2, pattern3, string.Empty);
string res = res3.TrimEnd(charsToTrim);
return res;
}
}
}