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|#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"
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
Post a Comment