I have these couple lines that I would like to match and right now I use multiple regexes to match them all, however I'm wondering if it is possible to match both in one regex:
@@Author:logan
//and these, three variations
@@tags:markdown,github,repetitivetag, tagwithsubtags:subtag, another:subtag:subtag2:repeating:this:repeating,repetitivetag,repetitivetag:withsubby,repetitivetag:withsubtag
@@tags:markdown;github;repetitivetag;tagwithsubtags:subtag,another:subtag:subtag2:repeating:this:repeating;repetitivetag;repetitivetag:withsubby;repetitivetag:withsubtag
@@tags:markdown;git-hub;repetitive-tag;tag_with_sub-tags:sub_tag,another:sub_tag:sub-tag2:repeating:this:repeat-_-_-ing;repetitive-tag;repetitive_tag:with_subby;repetitive_tag:with_subtag
What I do first is to match the @@NAME:VALUE part:
/^(?:@@)(\w+):(.*.)(?:\n+|$)/gm
let's say the first group is NAME and second group is VALUE.
If NAME is tags then I match the following regex in VALUE:
/(\w+)((?=,|;)|(:\w[\w|\-]+\w){0,}|)/g
This matches several groups that are like TAG;TAG;TAG ... or TAG,TAG,TAG ... in VALUE that we matched before
Then I match each TAG with this to get the SUBTAG
/(:)(\w[\w|\-]+\w)(?=:|)/g
Now that matches groups like :SUBTAG:SUBTAG:SUBTAG ... within TAG that we matched above
In Summary
I want to match
(@@)(NAME)(:)(VALUE)(TAG)(;)(TAG)(;)(TAG) ...in VALUE(:)(SUBTAG)(:)(SUBTAG))(;)in tag
example
@@Author:loganshould be able to getName = Author,Value = loganif value is multiple, like if its seperated by comma or semi-colon then matching something like
@@tags:tag1;tag2should be able to getName = Tags, `Value = ['tag1','tag2']if value has a subvalue such as
@@Author:logan:lastnameor this as its intended purpose
@@Tags:tag1:subtag;tag2:subtag1:subtag2should be able to get:Name = Author,Value = [{logan : [lastname]}]andName = Tags,Value = [{tag1 : [subtag]}, {tag2 : [subtag1, subtag2]}]
How can I match groups within groups and only if they exist?
,|;can be replaced with[,;]