I have a string that can come in different forms - one example below
%VAR('SERVER','DEFAULT') %VAR('LOC','NYC')Run_ServerRestart.ps1
I want to separate them as individual items and am not able to separate out the command in the end as a match. My regex returns 2 matches for the above example while I am looking to get 3 matches. Any ideas on what I maybe doing wrong and how to separate out them as below and if there is a more efficient way to achieve this ? We need to accommodate for spaces anywhere in between as well.
- %VAR('SERVER','DEFAULT')
- %VAR('LOC','NYC')
- Run_ServerRestart.ps1
Here is my regex so far:
/%VAR\(\s*'([^']+)'\s*\)*\,*\s*'([^']+)'\s*\)|/*\\*[\w-]+\s*\.?\S*/g
However, this above regex is not matching some of my examples below.
c:\abc\def.txt- should show 1 match%VAR('SERVER','USA')\C:\batch.bat- should show 2 matches -%VAR('SERVER', 'USA')and\c:\batch.bat%VAR('SERVER','NYC')- should show 1 match%VAR('SERVER','NYC') %VAR('APP','NNJ')Run_Command.ps1- should show 3 matches%VAR('SERVER','NYC') %VAR('APP','NNJ')andRun_Command.ps1%VAR('SERVER','NYC') -File- should show 2 matches -%VAR('SERVER','NYC')and-File/usr/bin/cat- should show 1 match%VAR('SERVER','NYC')BATCH1.bat- should show 2 matches -%VAR('SERVER','NYC')andBATCH1.batftp -s:D:\\apps\\scripts\\Intel\\daily_job.ftp- should show 1 match%VAR('SERVER')- should show 1 match
%VAR %VAR ... commandAre spaces between the %VARs required or optional?%VAR(a,b)%VAR(x,y)(var)+(command)?Thenvarandcommandneed to be broken down to match what a var looks like, and what a command looks like. A var is literal%VAR(quoted_stringcommaquoted_string)etc. This is how I break down what needs to be in a regex.