Regular expression to get a string between two strings in Javascript

前端 未结 11 2014
萌比男神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:20

    The method match() searches a string for a match and returns an Array object.

    // Original string
    var str = "My cow always gives milk";
    
    // Using index [0] would return
    // "**cow always gives milk**" str.match(/cow(.*)milk/)**[0]** // Using index **[1]** would return // "**always gives**" str.match(/cow(.*)milk/)[1]

提交回复
热议问题