I'm trying to get the number that follows the string "WK" in a string like "TF_6502BoM_WK47.xlsx". So far I have this regex pattern /WK[0-9]+/ but I'm only getting "WK47".
2 Answers
Sorry, your question is a little ambiguous, if you expand on your description we may be able to help more.
I've read this as you're trying to capture only the numbers? In which case you can do a named capture. The regex will parse the whole string and name the capture group containing the numbers so you can refer to it later in code.
var regex = new Regex("WK(?<numbers>\d+)");
var results = regex.Match("TF_6502BoM_WK47.xlsx");
System.WriteLine("Matched numbers: {0}", results.Groups["numbers"]);
(?<=WK)[0-9]+Demo