Jump to content
Sign in to follow this  
step887

Reg Ex help

Recommended Posts

step887

I try to parse some reg values to get out valid paths

Here are some examples

C:Windowssystem32cmd.exe /D /C start C:\Windows\System32\ie4uinit.exe ie4uinit.exe -ClearIconCache
%SystemRoot%system32regsvr32.exe /s /n /i:/UserInstall %SystemRoot%system32themeui.dll
C:PROGRA~2AvectoPRIVIL~1PGHook.dll,C:WindowsSysWOW64nvinit.dll
%SystemRoot%system32unregmp2.exe /ShowWMP
regsvr32.exe /s /n /i:U shell32.dll
 
Here is what I got
([(? :)|(%(.+?)%)].+?)?[^.|/]+.[^ |,]+
 
for the first one it returns 
             C:Windowssystem32cmd
             start C:\Windows\System32\ie4uinit.exe ie4uinit.exe
Second one 
            %SystemRoot%system32regsvr32.exe
             UserInstall %SystemRoot%system32themeui.dll
third one 
           C:PROGRA~2AvectoPRIVIL~1PGHook.dll
            ,C:WindowsSysWOW64nvinit.dll
fourth one work
 
fifth one returns 
             regsvr32.exe
             i:U shell32.dll
 
 
Any help would be appreciate
Edited by step887

Share this post


Link to post
Share on other sites
mikell

And what should precisely be the results for the provided examples ?

Edit

This is *a* possibilty, considering that "regsvr32.exe" is not a "valid path"

#Include <Array.au3>
$str = 'C:\Windows\system32\cmd.exe /D /C start C:\Windows\system32\ie4uinit.exe ie4uinit.exe -ClearIconCache' & @crlf & _
    '%SystemRoot%\system32\regsvr32.exe /s /n /i:/UserInstall %SystemRoot%\system32\themeui.dll' & @crlf & _
    'C:\PROGRA~2\Avecto\PRIVIL~1\PGHook.dll,C:\Windows\SysWOW64\nvinit.dll' & @crlf & _
    '%SystemRoot%\system32\unregmp2.exe /ShowWMP' & @crlf & _
    'regsvr32.exe /s /n /i:U shell32.dll'

$res = StringRegExp($str, '(?m)((?:[A-Z]:[^\s,]+)|(?:(?<=^|\h)%\S+))', 3)
_ArrayDisplay($res)
Edited by mikell

Share this post


Link to post
Share on other sites
step887

The valid path

 first one  
             C:Windowssystem32cmd
             C:Windowssystem32ie4uinit.exe
Second one 
            %SystemRoot%system32regsvr32.exe
             %SystemRoot%system32themeui.dll
third one 
           C:PROGRA~2AvectoPRIVIL~1PGHook.dll
           C:WindowsSysWOW64nvinit.dll
fifth one 
             regsvr32.exe
             shell32.dll
 
I am starting to think I should use stringregexpreplace with [/-].+?s to filters out the the switches in the middle
Edited by step887

Share this post


Link to post
Share on other sites
mikell

$res = StringRegExp($str, '(?m)((?:[A-Z]:[^\s,]+)|(?<=^|\h)(?:%\S+|[\w.]{4,}\h*(?=/|$)))', 3)

Share this post


Link to post
Share on other sites
step887

Thanks Mike, that works great for the listed ones

what about this one

rundll32.exe "C:Program Files (x86)Common FilesMicrosoft SharedVSTOvstoee.dll"

#include <array.au3?
$str = 'rundll32.exe "C:\Program Files (x86)\Common Files\Microsoft Shared\VSTO\vstoee.dll"'
$res = StringRegExp($str, '(?m)((?:[A-Z]:[^\s,]+)|(?<=^|\h)(?:%\S+|[\w.]{4,}\h*(?=/|$)))', 3)
_ArrayDisplay($res,@extended)

Returns C:Program

I tried to modify it but I am only a novice at at reg exp

Share this post


Link to post
Share on other sites
mikell

$res = StringRegExp($str, '(?m)((?:[A-Z]:.+?\.\w+)|(?<=^|\h)(?:%\S+|[\w.]{4,}\h*(?="|/|$)))', 3)

Regex need a preliminary precise definition of all the requirements, otherwise there will always be one particular case which will cause trouble

:)

Edited by mikell

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • gruntydatsun
      By gruntydatsun
      I have an XML file and every time there are three lines in a row with only <null/> in them, i want to insert a fourth line with <null/>.   Each line starts with 3 white spaces, followed by <null/> and ends with a white space followed by CR LF.   The presence of the three lines as described is unique to the points where I want to insert a line in this document.
       I'm trying to figure out how to apply the repeating part of a regex  {1,4} but apply it to this whole segment. 
      So far I have the below which picks up an individual line ok:
      ^\s{3}<null/>\s\r\n I tried wrapping it all in braces () then adding {3} but I'm obviously getting something wrong. 
      Attached is a section from the xml file with a block of nulls that should be matched if anyone would like to have a look.
      Help_From_Forum.xml
    • milkmoron
      By milkmoron
      I am trying to search in a web browser dates XX/XX/XXXX that are also links. I want to click them after and remove them from the array. This is all I have so far. Nothing shows up. What am I doing wrong?
      ControlFocus ("Customer Center", "", "")
      Local $aArray = StringRegExp('(..)/(..)/(....)', '(..)/(..)/(....)', $STR_REGEXPARRAYFULLMATCH)
      For $i = 0 To UBound($aArray) - 1
          MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 2 - " & $i, $aArray[$i])
      Next
       
    • WoodGrain
      By WoodGrain
      Hi All,
      I'd like to replace 'COMMA' with ',' for example:
      $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', ',') Now I've tried escaping the ',' in various ways unsuccessfully, such as:
      '[,]'
      "[,]"
      '\,'
      [,] seems to work in the pattern, I just can't figure out how to use it in the replace, and it seems everyone online is only interested in removing/replacing commas lol.
      I also tried creating and using a variable as the replacement but also didn't work:
      $myComma = "," $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', $myComma) I'm sure it's super simple if someone could point me in the right direction - thanks.
    • rcmaehl
      By rcmaehl
      Hi all,
      I still suck at regex as always and I need some help. According to the regex tester I normally use this should be working fine but it doesn't....
      StringRegExp($sString, "\A[1-9]+[0-9]*(\-[1-9]+[0-9]*)?,*\Z") I basically want to match:
      all numbers EXCEPT 0, but including 10, 20, etc with each number separated by a comma and allowing a "-" separated range as a value For example:
      1-5,7,10-12 I've spent a couple hours modifying it but I'm not sure where I've gone wrong. Any help would be appreciated!
    • ISI360
      By ISI360
      Hi!

      I need a little bit help from some RegEx experts please:
      I would make my ISN AutoIt Studio faster when generating the scripttree. And what would be better to do this via regex?
      Problem is i am not really good at this regex stuff. So maybe someone could help me here.
       
      The challange is to get all Global Variables from a script via RegEx in a Array.
      Here is a example script with some tests:
      Global $Var1 = 1234 Local $Local_Var = 1234 $Ignore_me_too = 1234 Global $Var2 = 1234, $var3 = 1242 Global $ahIcons[30], $ahLabels[30] Global Const $Var4 = iniread($inivar1,"jj","jj","") , $var5= iniread($inivar2,"jj","jj","") Global $Var_String = "was" Global $Array_Test[16] = [1,15,16,0,31,15,25,15,25,30,8,30,8,15,1,15] Global Enum $MARGIN_SCRIPT_NUMBER = 0, $MARGIN_SCRIPT_ICON, $MARGIN_SCRIPT_FOLD Global Const $Delim = '\', $Delim1 = '|' Global $hard1 = "a", _ $hard2 = "b", _ $hard3 = "c"  
      The returning array should look like this:
      $Var1 $Var2 $var3 $Var4 $var5 $Var_String $Array_Test $MARGIN_SCRIPT_NUMBER $MARGIN_SCRIPT_ICON $MARGIN_SCRIPT_FOLD $Delim $Delim1 $hard1 $hard2 $hard3  
      I already made some success with a expression i found in the SciTE Jump Tool:  (\$\w+)(?:[\h\[.=+*/^,)\-])?
      This nearly returns the perfect results. But it does not check if it´s a global variable (with the const and enum options) and also returns variables in commands (for example $inivar1)
      I also found this regex: (?im:^(?=Global|Const|Enum|Static)(?:Global)?\h*(?:Const|Enum|Static)?(?:(?<=Enum)\h+Step\h+[+*-]\d+)?\h*)([^\r\n .\=]+)
      This returns also usefull results...but trying to understand this explodes my head

      Maybe someone can help me here?
      Thanks in advance!
×