Regex - Capturing a Repeated Group

后端 未结 3 1947
死守一世寂寞
死守一世寂寞 2021-01-15 20:49

Alright, I\'ve read the tutorials and scrambled my head too much to be able to see clearly now.

I\'m trying to capture parameters and their type info from a function

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 21:02

    It's been a while since this question was active, but I think I finally found an answer.

    I think I was looking for the same situation as you, but for use with PHP, and there is an answer in another post I found that works really well, using the \K and \G commands from PCRE. See Alan Moore's answer here: PHP Regular Expression - Repeating Match of a Group

    My issue was trying to pull out all the cell values in a table, where each row contained a 6 digit number, 20x a 1 or 2 digit number, and an unrelated 1 or 2 digit number. The solution was:

    \s+(\d{6})<\/td>|\G<\/td>[^<>]*+\K\d{1,6}|(\d{1,2})<\/td>
    

    Very nice solution if I do say so myself!

提交回复
热议问题