Home  >  Q&A  >  body text

Regular expression - vim matchstr() cannot match the number in :4:

let a=['','']
echo matchstr(get(a,0),"[0-9] \+")
echo matchstr(get(a,1),"\d\+")
all display empty string


:s/\d\+/xxx/cg
can match 4
but the {pat} in matchstr() is unsuccessful!

大家讲道理大家讲道理2712 days ago486

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:40:50

    Brother upstairs, the first suggestion is correct. echo matchstr(get(a,0),"[0-9]+")It is indeed empty, there is no problem

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:40:50

    I haven’t written it before, but I feel it is a problem with "". It is recommended to try:
    1. Two \ For example: "[0-9]\+"
    2. Remove For example: "[0-9]+"

    reply
    0
  • Cancelreply