Jump to content

Regular expresion extracting a repeating sub pattern


Recommended Posts

If annyone still want to waste some time on regular expressions:

This pattern tryes to include those multiline hex values from a registry exported file. The "problem" at the moment is that it does not seem to bother about my last constaraint {2}. that is only extract keys with two values.

$regexp='(\[.+?\](?:\s|\z)+(?:".+?"=(?:.*\s{2,}|.*\z|(?:.*,\\\s{2,})+)+){2})'

The next problem is taht it crashes autoit if I replace the last {2} with {2,} and run it against a dump uf my HKEY_LOCAL_MACHINE.

Both problems are probably due to a screw up in the pattern.

The pattern is unreadable so here is a breakdown:

\[.+?\](?:\s|\z)+
Extract the key part

".+?"=
Extract the value name

(?:.*\s{2,}|.*\z|(?:.*,\\\s{2,})+
Extract the data part. This has tree posibilities .*\s{2,} the normal case, .*\z the end of file case, (?:.*,\\\s{2,})+ data spanning multiple lines case.

I'm out of time for the evening. But any input onthe pattern is welcomed. Especially if anyone could explain why it does not obey the last {2} or why it crash (could be due to memory constraints).

Uten

Link to comment
Share on other sites

Hi Uten,

please define exactly what you want to catch from the *.reg file.

If I understood you right now, you want to catch the multiline entries like the value from "InprocServer32" below:

Windows Registry Editor Version 5.00
;   14.01.2008 19:25:56  -  14.01.2008 19:27:12

; ADD section
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{B722BCCD-4E68-101B-A2BC-00AA00404770}\InprocServer32]
@="C:\\Programme\\Gemeinsame Dateien\\Microsoft Shared\\OFFICE12\\MSO.DLL"
"InprocServer32"=hex(7):7b,00,28,00,4d,00,76,00,57,00,34,00,79,00,24,00,41,00,\
  24,00,21,00,21,00,21,00,21,00,21,00,4d,00,4b,00,4b,00,53,00,6b,00,50,00,50,\
  00,54,00,56,00,69,00,65,00,77,00,65,00,72,00,43,00,6f,00,6e,00,76,00,65,00,\
  72,00,74,00,65,00,72,00,31,00,32,00,44,00,65,00,70,00,65,00,6e,00,64,00,65,\
  00,6e,00,63,00,69,00,65,00,73,00,3e,00,74,00,57,00,7b,00,7e,00,24,00,34,00,\
  51,00,5d,00,63,00,40,00,24,00,21,00,28,00,53,00,27,00,78,00,61,00,54,00,4f,\
  00,35,00,00,00,49,00,6e,00,2c,00,4e,00,56,00,6e,00,2d,00,7d,00,66,00,28,00,\
  5a,00,58,00,66,00,65,00,41,00,52,00,36,00,2e,00,6a,00,69,00,57,00,4f,00,52,\
  00,44,00,56,00,49,00,45,00,57,00,46,00,69,00,6c,00,65,00,73,00,3e,00,49,00,\
  56,00,4f,00,32,00,38,00,25,00,64,00,74,00,77,00,38,00,51,00,78,00,56,00,65,\
  00,4a,00,32,00,51,00,55,00,63,00,4e,00,00,00,00,00


[HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt]
"InstallDir"="C:\\Programme\\AutoIt3"
"Version"="v3.2.10.0"

If you've studied my 'RegTo.au3', you would have seen my solution ...

$sRegFile = FileRead(FileOpen(@ScriptDir & '\example.reg', 0))
$sRegFile = StringRegExpReplace(FileRead($fhRegFile), '(\\\r\n  )', '')

This line will delete all linebreaks.

Greetz

Greenhorn

Edited by Greenhorn
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...