Regex for "111 & # 8594; c: \ my source \ file1.cpp (without code)" (C #)
I need to parse a string with the following contents in C #:
111 -> c:\my source\file1.cpp (no code)
112 -> c:\my source\file1.cpp
113 -> c:\my source\file2.cpp
114 -> c:\my source\file3.cpp
115 -> c:\my source\file2.cpp (no code)
I need to get the first number and file names, but only for entries with code (so there shouldn't be (without code) at the end. Currently, I ended up with this rexex
new Regex(@"^(\d+) -> ([^\r\n]*)", RegexOptions.Multiline | RegexOptions.IgnoreCase)
It is really simple, but it gives me lines that I do not want to see. All my attempts to write something like ^(\d+) -> ([^\r\n]*)(?! \(no code\))failed. This may actually be a more general example. Similar: How to match BBBs in the form line “aaa BBB ccc” , where BBB can be any character set, and aaa and ccc are known tokens that consist of the same character set as in the BBB?
#, .
new Regex(@"^(\d+)\s->\s(.+\.\w+)(?!.*\(no code\))$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
, ,
^(\d+) -> ([^\r\n]*)(?! \(no code\))
, ([^\r\n]*) , lookahead .
Update:
@Brad Christie
new Regex(@"^(\d+) -> (.+?)(?<! \(no code\))$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
.net/# , +1