javascript - how to exclude part of string from regex matching (arabic dictionary examples) -


i have string this:

var str = "translation1; translation2; اللغة العربية example1; اللغة العربية example2; اللغة العربية example3; اللغة العربية example4; اللغة العربية example5; اللغة العربية example6; اللغة العربية example7; اللغة العربية example8; اللغة العربية example9"; 

it's word translations, after them goes examples, witch identify arabic letters between 2 semicolons. need separate between translations , examples, , array examples:

["اللغة العربية example1", "اللغة العربية example2", .... ] 

i tried code:

var str = "translation1; translation2; اللغة العربية example1; اللغة العربية example2; اللغة العربية example3; اللغة العربية example4; اللغة العربية example5; اللغة العربية example6; اللغة العربية example7; اللغة العربية example8; اللغة العربية example9;";   var match = "";  var example_pattern = /;([\s\s]+?[ا-ي]+?[\s\s]+?);/ig  var examples = [];  while (match = example_pattern.exec(str)) {                      examples.push(match[1]);                       example_pattern.lastindex --;                   }  console.log(examples);

but returns examples[0] = "translation2; اللغة العربية example1;".

how remove "translations2;" matching in example1?

rest of elements executes fine.

(i made example_pattern.lastindex --; because without code returns array 1st, 3d, 5th, 7th, 9th examples. may there way make regexp example_template better)

it stupid mistake. fixed problem removing \s in beginning of regex "example_pattern"


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -