How to match everything up to the second occurrence of a character?

前端 未结 2 600
深忆病人
深忆病人 2020-12-15 17:49

So my string looks like this:

Basic information, advanced information, super information, no information

I would like to capture everything

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 18:14

    This will capture up to but not including the second comma:

    [^,]*,[^,]*
    

    English translation:

    • [^,]* = as many non-comma characters as possible

    • , = a comma

    • [^,]* = as many non-comma characters as possible

    [...] is a character class. [abc] means "a or b or c", and [^abc] means anything but a or b or c.

提交回复
热议问题