아래 정규식이 문자열과 일치하면 코드가 작동합니다. 문자 중 하나가없는 경우 (예 : MONEY-STAT가 누락 된 경우)정규식 누락 문자
string s = "MONEY-ID123456:MONEY-STAT43:MONEY-PAYetr-1232832938";
Regex regex =
new Regex(@"MONEY-ID(?<moneyId>.*?)\:MONEY-STAT(?<moneyStat>.*?)\:MONEY-PAYetr-(?<moneyPaetr>.*?)$");
Match match = regex.Match(s);
if (match.Success)
{
Console.WriteLine("Money ID: " + match.Groups["moneyId"].Value);
Console.WriteLine("Money Stat: " + match.Groups["moneyStat"].Value);
Console.WriteLine("Money Paetr: " + match.Groups["moneyPaetr"].Value);
}
Console.WriteLine("hit <enter>");
Console.ReadLine();
일치하지 않습니다와'내에서 코드를 실행하지 않을 경우 (match.Success) {...}' – Qiau
혼자서 시도하지 않으시겠습니까? –
문자열이 작동하지 않으면 @Steve B가 작동하지 않습니다. 정규 표현식 문자열로 변경할 수있는 것은 무엇입니까? – Alvin