You can make the regex pattern into numbering
+ wording
+ commaing
.
I made a code to print out words that match.
The pattern is \d+.*?(?=,)
, and the regex here is *?
and positive lookahead, which are Lazy quantifiers.
\d+
corresponds to number
.*?
corresponds to with the word
. (Use the Lazy Quantifier)
(?=,)
corresponds to having a comma.
using System.Text.RegularExpressions;
public class Hello1 {
public static void Main() {
string input = ",123 asdf,456 ghjk,zxcv";
Regex regex = new Regex(@"\d+.*?(?=,)");
Match m = regex.Match(input);
while (m.Success)
{
System. Console.WriteLine("{0}:{1}", m.Index, m.Value);
m = m.NextMatch();
}
}
}
If you can interpret English to some extent, we recommend the https://regex101.com/ site to use Regex.
© 2024 OneMinuteCode. All rights reserved.