Jump to content
Sign in to follow this  

Reg Ex help

Recommended Posts

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
%SystemRoot%system32unregmp2.exe /ShowWMP
regsvr32.exe /s /n /i:U shell32.dll
Here is what I got
([(? :)|(%(.+?)%)].+?)?[^.|/]+.[^ |,]+
for the first one it returns 
             start C:\Windows\System32\ie4uinit.exe ie4uinit.exe
Second one 
             UserInstall %SystemRoot%system32themeui.dll
third one 
fourth one work
fifth one returns 
             i:U shell32.dll
Any help would be appreciate
Edited by step887

Share this post

Link to post
Share on other sites

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


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)
Edited by mikell

Share this post

Link to post
Share on other sites

The valid path

 first one  
Second one 
third one 
fifth one 
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

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)

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

$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

    • By BlueBandana
      Is there a way to output the regex matches into a file?
      I have a script to compare two files and check for regex matches.
      I want to output the matching regex of 'testexample.txt' to another file.
      #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next  
    • By guner7
      I need some help to parse the Green highlighted value with from below text:
      RESISTOR  THICK FILM 4.64K ±1% 1/4W ±100PPM/°C 1206 SMT
      RESISTOR  THICK FILM 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT
      RESISTOR  THICK FILM 0   1/8W  0805 SMT
      I am using positive look behind.:
      (?<=FILM|WOUND|OXIDE).+ Can only pull this off:
      4.64K ±1% 1/4W ±100PPM/°C 1206 SMT 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT 22K ±10% 1/2W AXIAL THT  22 ±5% 3W ±30PPM/°C AXIAL THT 4.7K ±5% 2 W ±300PPM/°C AXIAL THT 0   1/8W  0805 SMT I'm trying the \b word boundary to no avail at this point. Appreciate if anyone would guide me on this?
    • By junichironakashima
      Im creating a code that will work in this sequence:
      1. Copy the text (question) in one atea of the screen
      2. Catch the 2 strings (number)
      3. Multiply the 2 strings ( $1*$2)
      4. Click the next area to put the answer
      5. Paste the answer
      This is my code
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      $x = StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2")
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1)
      However the output is this
      How can I make it solve itself? Because I tried this code:
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1) $x = Execute(StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2"))
      Output is just blank text

    • 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.
    • 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])
  • Create New...