What regular expression can I use to find the Nᵗʰ entry in a comma-separated list?

前端 未结 3 2137
无人及你
无人及你 2021-01-02 12:04

I need a regular expression that can be used to find the Nth entry in a comma-separated list.

For example, say this list looks like this:



        
3条回答
  •  不知归路
    2021-01-02 12:23

    You could use something like:

    ([^,]*,){$m}([^,]*),
    

    As a starting point. (Replace $m with the value of (n-1).) The content would be in capture group 2. This doesn't handle things like lists of size n, but that's just a matter of making the appropriate modifications for your situation.

提交回复
热议问题