How about this: <.{4}F[^>]+>
It matches the opening <
, followed by any 4 chars, F, then anything till the closing >
(by matching anything that is not a >
).
string input = "<2342Flsdn3Z><9124Fsflj20>";
string pattern = "<.{4}F[^>]+>";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine(m.Value);
}
EDIT: part of making a good regex is clearly specifying the pattern you want to match. For example, the way you worded the question leaves certain details out. I responded with my pattern to match any character as long as F was where you specified.
For a better regex you could've told us a number of things:
- Chars before F will always be digits and of length 4:
\d{4}
or [0-9]{4}
- Chars after F will be of X length (6?) and can only be numbers and letters:
[\dA-Z]{6}
- Case is insensitive: use
RegexOptions.IgnoreCase
(.NET) or use [a-zA-Z]
- State your intention: are you matching it? Trying to extract the inner value? What do you mean by split? Split on what?
- Specify the language you're using: C#, Python, Perl, etc. (you did this one)