Regex start searching from the end of the string (reverse)

前端 未结 2 1251
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 18:36

I have strings that have blocks enclosed in underscores in them. Example:

*Text* _word_ it is something we read every day. _Words in texts_ can be really exp         


        
相关标签:
2条回答
  • 2020-12-16 18:58

    The text between the second last _ and the end of the string should be matched

    Use a negated character class, like

    ([^.]*$)
    

    It will match everything from the end of the string that isn't ., resulting in the last quote (assuming each quote ends with a .)

    http://regex101.com/r/fA3pI7/1

    0 讨论(0)
  • 2020-12-16 19:11

    Have a try with:

    ((?:_[^_\r\n]*){2})$
    

    It matches an underscore followed by any number of any character that is not underscore or line break, all that occurs twice before the end of lien.

    0 讨论(0)
提交回复
热议问题