Extract hashtags from complex string using regex

后端 未结 2 795
無奈伤痛
無奈伤痛 2020-12-21 15:42

I have a crazy string, something like:

sun #plants #!wood% ##arebaba#tey   travel#blessed    #weed das#$#F!@D!AAAA

I want to extract all \"

2条回答
  •  有刺的猬
    2020-12-21 16:22

    Just using match you could get all the group 1 matches into an array.

    (?:^|[ #]+)([^ #]+)(?=[ #]|$)

    Easy!

     (?: ^ | [ #]+ )
     ( [^ #]+ )                    # (1)
     (?= [ #] | $ )
    

    Or, if you feel it's this simple, then just use ([^ #]+) or [^ #]+
    which gets the same thing (like split in reverse).

提交回复
热议问题