Search code examples
regexibm-doors

REGEXP : find the first character after one specific other character


this is my problem :

I have a similar list of strings like that :

1) mytext-othertext-01-Onemore
2) mytext1-othertext1-02-Twomore
3) mytext2-othertext2-03-Fourmore
4) ...

I'm tryng to get ONLY the FIRST character after the third "-" in my text so the result would be :

1) O => because mytext-othertext-01-Onemore
2) T => because mytext1-othertext1-02-Twomore
3) F => because mytext2-othertext2-03-Fourmore

I'm pretty bad using regexp and i assume that is not probably a hard one but i'm stuck with this at the moment :

\-(.*)

Example of result

That will took the entire text after the first "-" as you can see

Help will be hardly appreciated to solve my problem.


Solution

  • ^(?:[^-]*-){3}(.)
    

    [^-]*- matches a sequence (possibly empty) of non-hyphens followed by hyphen. {3} after that matches it 3 times, so it finds the 3rd hyphen, and ^ at the beginning makes it start matching from the beginning of the string. The capture group (.) captures the next character.

    DEMO