1
 _, _, XYZ, Path, filename  = string.find("re32:HKEY_LOCAL_MACHINE\\SOFTWARE\\XYZ\\Assistant\\Active ", "(%w+):(.+)\\(.*)")

print(XYZ)  
print(Path)    
print(filename)

The above code outputs:

 re32
 HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\Assistant\
 Active

I need the output in below form--that is, instead of three groups, I need four:

re32
HKEY_LOCAL_MACHINE
SOFTWARE\XYZ\Assistant\
Active

What has to be done in this case?

0

4 Answers 4

1
XYZ, RootKey, Path, filename = ([[re32:HKEY_LOCAL_MACHINE\SOFT WARE\XYZ\Assistant\Active ]]):match ( [[(%w+):([^\]+)(.+)\(.*)]])

Use [[]] instead of "" to stop escape sequences.

Sign up to request clarification or add additional context in comments.

Comments

0
_, _, XYZ, RootKey, Path, filename = string.find("re32:HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\Assistant\Active ", "(%w+):(.-)\(.+)\(.*)")

print(XYZ)
print(RootKey)
print(Path)
print(filename)

Should produce

re32

HKEY_LOCAL_MACHINE

SOFTWARE\\XYZ\\Assistant\\

Active

10 Comments

_, _, XYZ,test, Path, filename = string.find("re32:HKEY_LOCAL_MACHINE\\SOFTWARE\\XYZ\\Assistant\\Active ", "(%w+):(.+)\(.+)\(.*)" ) Print(XYZ) Print(test) Print(Path) Print(filename)
@Chet, you'll need to also add another variable for additional group you created
Please verify Second and third group has to be reversed
Getting output with your suggestion: re32 HKEY_LOCAL_MACHINE\\SOFTWARE\\XYZ Assistant Active Expected : re32 HKEY_LOCAL_MACHINE SOFTWARE\\XYZ\\Assistant Active
Getting output with your suggestion: re32 HKEY_LOCAL_MACHINE\\SOFTWARE\\XYZ Assistant Active Expected : re32 HKEY_LOCAL_MACHINE SOFTWARE\\XYZ\\Assistant Active
|
0

You can have named groups in regular expressions. example:- (/group1\[0-9])(abc) (replace "/" with "<" and "\" with ">" in above example) this regx will match "3abc" and you can get the matched number by choosing the group name(group1) in the match. refeer this http://www.regular-expressions.info/named.html

2 Comments

Regex in LUA I need yoy are talking about C#
PLEAse help with the LUA Regex
0
_, _, XYZ, RootKey, Path, filename = string.find(
    "re32:HKEY_LOCAL_MACHINE\\SOFTWARE\\XYZ\\Assistant\\Active ",
    "(%w+):(.-)\\(.+\\)(.*)")

print(XYZ)
print(RootKey)
print(Path)
print(filename)

output:

re32
HKEY_LOCAL_MACHINE
SOFTWARE\XYZ\Assistant\
Active 

See it on ideone.com

This answer is essentially the same as Serge's, but the backslashes are properly escaped in the target and pattern strings, and the final backslash is included the third capturing group.

But most importantly, this solution is tested. Ideone FTW!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.