oracle 12c - select string after last occurrence of a character

前端 未结 5 1764
旧时难觅i
旧时难觅i 2020-12-11 02:27

I have below string:

ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence

So I want to select Sentence since it is the string a

5条回答
  •  Happy的楠姐
    2020-12-11 03:06

    Just for completeness' sake, here's a solution using regular expressions (not very complicated IMHO :-) ):

    select regexp_substr(
      'ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence',
      '[^.]+$') 
    from dual
    

    The regex

    • uses a negated character class to match anything except for a dot [^.]
    • adds a quantifier + to match one or more of these
    • uses an anchor $ to restrict matches to the end of the string

提交回复
热议问题