I have a specific pattern I want to follow but the extraction process is not working as expected. I assume the pattern I developed is not correct, but I can't find the issue in it.
I have the string string test1 = "R1 0.1uF" and the pattern
"(?<des>^[a-zA-Z]+)|(?<number>\d+\s+)|(?<val>[0-9]*.?[0-9]+)|(?<units>[^,]*)";
I want it to be extracted as follows:
des: R
number: 1
val: 0.1
units: uF
Currently, des is working properly and it's finding R but the others return an empty string.
Here's my code
const string pattern = @"(?<des>^[a-zA-Z]+)|(?<number>\d+\s+)|(?<val>[0-9]*.?[0-9]+)|(?<units>[^,]*)";
string test1 = "R1 0.1uF";
Regex r = new Regex(pattern, RegexOptions.Compiled);
Match m = r.Match(test1);
string des = m.Groups["des"].Value;
string number = m.Groups["number"].Value;
string val = m.Groups["val"].Value;
string units = m.Groups["units"].Value;
|? That means "OR" -- it's matching thedesbit, and then because that matched, it's not trying any of the other bits|and make it a bit more specific^(?<des>[a-zA-Z]+)(?<number>[0-9]+)\s+(?<val>[0-9](?:\.[0-9]+)?)(?<units>[^,]*)