问题
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/
回答1:
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
来源:https://stackoverflow.com/questions/53636059/regex-get-nth-character-between-two-delimiters