Search code examples
regexoracle11gregular-language

Regex: Get nth character between two delimiters


I have an example string

1836248_NNY_01.pdf

but it can also be

18362481_YYN_102.pdf

And I need to get the nth character between the two underscores.

So far my regex is \_(.*?)\_ to get the characters between the underscores. But following up I can't figure out how to get the 2nd N for example.

https://regex101.com/r/XUMKyf/1/


Solution

  • You could use \_.{1}(.).*\_ and replace the 1 with whatever you want.
    So 0 would be the first char, 1 the second, and so on.

    Example: https://regex101.com/r/XUMKyf/3