I have a string that contains a header with a length of the following field.
Example:
fillerfillerCA20 abcdefghijklmnopqrst CA5 zyxwvfillerfiller
I need to find the two values: abcdefghijklmnopqrst and zyxwv
I was going to use a backreference to get the length for the quantifier:
(?i)ca(?<length>\d+?)\x20.{\k<length>}\x20?
but apparently, using a backreference in a quantifier is not supported.
How can I accomplish this?
Not in one step. Regular expressions cannot be self-referential. They are first built, and then used. No re-building/augmenting is possible once the regex is built.
You can match the length info as you already do and use it in a second step, while evaluating the matches.
Preemptive comment: I know that one can do "(.)\1"
to match the same character twice. This is not what I mean with "self-referential", though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With