Regular expression to get a string between two strings in Javascript

前端 未结 11 2142
萌比男神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条回答
  •  不要未来只要你来
    2020-11-21 07:05

    A lookahead (that (?= part) does not consume any input. It is a zero-width assertion (as are boundary checks and lookbehinds).

    You want a regular match here, to consume the cow portion. To capture the portion in between, you use a capturing group (just put the portion of pattern you want to capture inside parenthesis):

    cow(.*)milk
    

    No lookaheads are needed at all.

提交回复
热议问题