P
P
Peter2016-01-27 23:34:32
JavaScript
Peter, 2016-01-27 23:34:32

How to get an array of search strings in a string?

There is text (regular string)

Lorem ipsum 'vendor/js/srcipt.js' dolor sit amet,  'lib/ls/jquery/jquery.min.js' consectetur 'img/pict.jpg' adipisicing 'vendor/style/some-style.min.css' elit. Adipisci, tenetur?

From it you need to get an array of links that start with vendorand end with jsor css, but without the word vendor
. in the end it should turn out like this:
['js/srcipt.js', 'style/some-style.min.css']
How to do it?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OVK2015, 2016-01-28
@volkov_p_v

var testStr = "Lorem ipsum 'vendor/js/srcipt.js' dolor sit amet,  'lib/ls/jquery/jquery.min.js' consectetur 'img/pict.jpg' adipisicing 'vendor/style/some-style.min.css' 'vendor/style/some-style.less' или 'vendor/img/bla.png' elit. Adipisci, tenetur?";
var reqExpWrapper = new RegExp('(?:vendor/)((?:.*?)\\.(?:css|js))\'', 'g');

var matches = new Array();

while(match = reqExpWrapper.exec(testStr))
{
  matches.push(match[1]);
}
console.log(matches);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question