Regex for Managed Metadata Format (Multiple Values) -


i have got regex gives description of single input value:

(?:gtset|gp0|gpp|l0)\|#0[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]*\|(.*)  l0|#060066230-11f1-46db-ad89-2b91ffd42ec4|processing 

but when comes multiple values - doesnt work - whats missing ?

gp0|#3e7ea87a-6d25-4f18-a68a-3ccb18f72e57;l0|#03‌​e7ea87a-6d25-4f18-a6‌​8a-3ccb18f72e57|argu‌​mentationshilfen;gts‌​et|#25b6d12b-8e8b-42‌​33-8931-9c50587ca114‌​;gp0|#84e33f19-dc80-‌​4628-b292-a96090b1c7‌​02;l0|#084e33f19-dc8‌​0-4628-b292-a96090b1‌​c702|medien (videos/grafiken/bilder)  gp0|#3e7ea87a-6d25-4f18-a68a-3ccb18f72e57;l0|#03e7ea87a-6d25‌​-4f18-a68a-3ccb18f72‌​e57|argumentationshi‌​lfen;gtset|#25b6d12b‌​-8e8b-4233-8931-9c50‌​587ca114;gp0|#84e33f‌​19-dc80-4628-b292-a9‌​6090b1c702;l0|#084e3‌​3f19-dc80-4628-b292-‌​a96090b1c702|medien (videos/grafiken/bilder);gp0|#a8629bc7-a09f-4c45-a864-8506e0‌​01ef66;l0|#0a8629bc7‌​-a09f-4c45-a864-8506‌​e001ef66|technische daten" 

you need restrict (.*) pattern matches 0+ chars other line breaks negated character class matches 1+ chars other ;, [^;]+ (since seems delimiter values need extract).

use

(?:gtset|gp0|gpp|l0)\|#0[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]*\|([^;]+) 

see regex demo. note contracted pattern bit merging 3 -[0-9a-f]{4} (?:-[0-9a-f]{4}){3} (3 occurrences of -<4_hex_chars> sequences).

var rx = /(?:gtset|gp0|gpp|l0)\|#0[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]*\|([^;]+)/g;  var strs = [ 'l0|#060066230-11f1-46db-ad89-2b91ffd42ec4|processing', 'gp0|#3e7ea87a-6d25-4f18-a68a-3ccb18f72e57;l0|#03e7ea87a-6d25-4f18-a68a-3ccb18f72e57|argumentationshilfen;gtset|#25b6d12b-8e8b-4233-8931-9c50587ca114;gp0|#84e33f19-dc80-4628-b292-a96090b1c702;l0|#084e33f19-dc80-4628-b292-a96090b1c702|medien (videos/grafiken/bilder)', 'gp0|#3e7ea87a-6d25-4f18-a68a-3ccb18f72e57;l0|#03e7ea87a-6d25-4f18-a68a-3ccb18f72e57|argumentationshilfen;gtset|#25b6d12b-8e8b-4233-8931-9c50587ca114;gp0|#84e33f19-dc80-4628-b292-a96090b1c702;l0|#084e33f19-dc80-4628-b292-a96090b1c702|medien (videos/grafiken/bilder);gp0|#a8629bc7-a09f-4c45-a864-8506e001ef66;l0|#0a8629bc7-a09f-4c45-a864-8506e001ef66|technische daten'];    (var s of strs) {    var res = [], m;    while (m=rx.exec(s)) {       res.push(m[1]);    }    console.log(res);  }

also, note (?:gtset|gp0|gpp|l0) group better written (?:g(?:tset|p[0p])|l0) avoid redundant backtracking.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -