Why doesn't finite repetition in lookbehind work in some flavors?

前端 未结 4 1258
臣服心动
臣服心动 2020-12-10 21:11

I want to parse the 2 digits in the middle from a date in dd/mm/yy format but also allowing single digits for day and month.

This is what I came up with

4条回答
  •  孤城傲影
    2020-12-10 21:47

    Unless there's a specific reason for using the lookbehind which isn't noted in the question, how about simply matching the whole thing and only capturing the bit you're interested in instead?

    JavaScript example:

    >>> /^\d{1,2}\/(\d{1,2})\/\d{1,2}$/.exec("12/12/12")[1]
    "12"
    

提交回复
热议问题