To identify such lines, try this pattern: (?m)^\d{2}\d{1,2}\d{1,2}\d([A-Z])\d+
.
After finding the lines using Regex.Matches, use match.Groups[1] to extract the letter.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have the following string/line to be found in the text made of hundred lines:
8109264F2304300BLA
81 (year) 09 (month) 26 (day) 4 (control digit) F (the value I need) 2304300 (foo value) BLA (sometimes it's not even contained in the string)
Meaning sometimes it could be 8109264F2304300.
What could be the regex that would first find this string and then fetch the letter F (it could be another letter as well) ??
Thank you so much
P.S. this is a chunk of the text that I need to search...
ARCHEEA0000000000003100<<<<<<<
8109264F2304300BLA<<<<<<<<<<<6
BLAH<<BLAH2<<<<<<<<<<<<<<
To identify such lines, try this pattern: (?m)^\d{2}\d{1,2}\d{1,2}\d([A-Z])\d+
.
After finding the lines using Regex.Matches, use match.Groups[1] to extract the letter.
Hi
Not a regex patter/match, but perhaps you don't need the complexity of that. Here is an alternative that may be of use.
Assuming you already have a means to isolate the line you want to check.
' EXAMPLE
Dim checkline As String = "8109264F2304300BLA<<<<<<<<<<<6"
Dim result As String = checkline.Substring(7, 1)
Hello LesHay,
Actually I might already found the answer. I just noticed that it's consisted of 7 digits then 1 letter and then again 7 digits so I wrote the following regex:
var rgxGender = new Regex(@"\d{7}[A-Z]\d{7}");
It seems to be working fine. Of course once I found the match I substring the 8th character as you pointed out. Thank you
A tool like Regex Editor for Visual Studio is really useful for questions like this. Here's my first pass at a RE that matches the value and captures the subset you want. Note that I'm assuming there is only 1 match per line.
regex = new Regex(@"\d{7}(?<letter>[a-z])", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
var match = regex.Match(input);
if (match.Success)
{
var letter = match.Groups["letter"]?.Value;
};
In your example there are actually 2 matches within your string input. My regex only covers the portion of the string you mentioned. The foo+ values you weren't specific about so I left them out. If there is a pattern after the letter then you should expand the pattern to encompass that as well.