开发者

Regular expression for tokenizing an argument list (VBScript)

I'm trying to create a regular expression that will tokenize a string of the following format: Program.EXE someparam:[[REG|HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows]] someotherparam[[DATA|User]] couldbeanotherparam

The regular expression I'm looking for is to get all [[REG|any tex开发者_Go百科t]] OR [[DATA|any text]] occurrences in my string.

My main problem is to treat each instance as a separate token. When trying something like [[REG\|.+]] it the first occurrence of [[ and the last occurrence of ]] as the expression boundaries. I suppose it has to do with the .+.

The result I'm looking for in the example above is: [[REG|HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows]] [[DATA|User]]


Repeaters are greedy by default:

[[(REG|DATA)\|.+?]]

Adding the question mark makes it as ungreedy as possible so it will stop at the first instance of "]]" it can find.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜