Find a word before one of two possible separators

后端 未结 4 1012
故里飘歌
故里飘歌 2021-01-19 02:45
word:12335
anotherword:2323434
totallydifferentword/455
word/32

I need to grab the character string before the : or / usi

4条回答
  •  醉梦人生
    2021-01-19 03:21

    Something like this would do the trick in Ruby http://rubular.com/r/PzVQVIpKPq

    ^(\w+)(?:[:\/])
    

    Starting from the front of the string, grab any word characters and capture them, until you reach the non-capturing / or :

提交回复
热议问题