I have the following code which attempts to match all strings like "*SOMESTRING" (which can include numeric values), but not "*SOMESTRING*". For this I am using a negative lookahead as follows;
*AN01ZORA should match,
\*PCCL\* should not match.
string s = " if 'L,....' MDC = '13' Then " + " if 'B,960.' SEX NOT = '2' AND *SEX NOT = '3' Then " + " DRG = 960Z (UNGROUPABLE) " + " GoTo MDC FldErr " + "Else if 'B,N01.' SRG IN TABLE(*AN01ZORA) Then " + " if '.,N01.' *PCCL* > 2 Then "; Regex rr = new Regex(@"(?i)(?!\*\w+\*)\*\w+"); MatchCollection mc = rr.Matches(s); foreach (Match m in mc) m.ToString().Dump();
Output: *SEX *AN01ZORA
This seems to produce the correct output, but feels nasty and not correct. Is this right and what could I do to make the