I have made a regex, but I can't make it to match in order.
var $result = [];
var url_check = "CentOS-7-x86_64-LiveGNOME-1804";
var torrent_forbidden = ["CentOS-7 live", "Centos 7 livegnome", "Cent-7", "OS Cent-7", "centos:7", "centos word:7", "centos:6", "cento 7 s"];
jQuery.each(torrent_forbidden , function(index, torrent_forbidden) {
var regex = new RegExp('^(?=.*?' + torrent_forbidden.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').split(/\\?[\s,_.:*-]+/).join(')(?=.*?') + ')', 'gi');
if(regex.test(url_check) === true){
$result.push(torrent_forbidden + ' : true');
}else{
$result.push(torrent_forbidden + ' : false');
}
});
console.log($result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Here is what I expect to obtain as result in the string CentOS-7-x86_64-LiveGNOME-1804
:
|-----------------------------------------|
| Search | Result | Expected |
|-----------------------------------------|
| CentOS-7 live | true | false |
| Centos 7 livegnome | true | true |
| Cent-7 | true | false |
| OS Cent-7 | true | false |
| centos:7 | true | true |
| centos word:7 | false | false |
| centos:6 | true | false |
| cento 7 s | true | false |
|-----------------------------------------|