Regular expression to get a string between two strings in Javascript

前端 未结 11 2139
萌比男神i
萌比男神i 2020-11-21 06:29

I have found very similar posts, but I can\'t quite get my regular expression right here.

I am trying to write a regular expression which returns a string which is b

11条回答
  •  萌比男神i
    2020-11-21 07:19

    • You need capture the .*
    • You can (but don't have to) make the .* nongreedy
    • There's really no need for the lookahead.

      > /cow(.*?)milk/i.exec('My cow always gives milk');
      ["cow always gives milk", " always gives "]
      

提交回复
热议问题