samedi 5 août 2017

RegEx match (named) groups that show up in random order (Python re)

I'm trying to do a match of RegEx named groups (preArgs, apm1Args, midArgs, apm2Args, postArgs) listed in the regEx below, that appear in random order.
I'm able to match Test String1, but not the Test String2 below:

I need to satisfy the following requirements: 1. Each of the group may be present 1 or more (because of the leftover junk); or it's absent altogether...

2. Each of the apm1Args and apm2args always appear with 1 or more -D switches in addition to unique javaagent jars.

I tried some OR (|) options, (?=) positive look ahead, but no luck and getting lost in the maze... My Trials:

RegEx (available at: RegEx listed at regex101.com)

^(?P<preArgs>.*)(?P<apm1Args>-javaagent:.+\/agent1\.jar\s+(?:-Dvendor1\.agent1\.\S+\s*)*)(?P<midArgs>.*)(?P<apm2Args>-javaagent:.+\/agent2\.jar\s+(?:-Dvendor2\.agent2\.\S+\s*)*)(?P<postArgs>.*)$

Test String 1

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777 -javaagent:/path1/to/agent1.jar -Dvendor1.agent1.applicationName=app123 -Dvendor1.agent1.tierName=myTier1 -Dvendor1.agent1.nodeName= -Dvendor1.agent1.uniqueHostId=myHost1 -Xgcpolicy:gencon -javaagent:/path2/to/vendor2/agent2.jar -Dvendor2.agent2.agentProfile=/metlife/runtime/installed/apm/profiles/csa.profile -Dvendor2.agent2.customValue1=myValue2

Test String2 (available at: same RegEx with a different regex101.com link)

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777 -javaagent:/path2/to/vendor2/agent2.jar -Dvendor2.agent2.agentProfile=/metlife/runtime/installed/apm/profiles/csa.profile -Dvendor2.agent2.customValue1=myValue2 -javaagent:/path1/to/agent1.jar -Dvendor1.agent1.applicationName=app123 -Dvendor1.agent1.tierName=myTier1 -Dvendor1.agent1.nodeName= -Dvendor1.agent1.uniqueHostId=myHost1 -Xgcpolicy:gencon




Aucun commentaire:

Enregistrer un commentaire