Jump to content
Sign in to follow this  
gcue

or statement in a regexp?

Recommended Posts

gcue

can an or be said in a regexp statement?

for example in this text i want to capture text AFTER "Login Script:" (note: each new line after ONLY if the first word is "map" OR "@NET"

Login Script:

map k:=lo-ncs_users2_server\users2:

@NET USE x: \\loap01\tes

Login Time: 05:09:48 am 03/11/10

modifiersName: CN=CGNDSDR1

Edited by gcue

Share this post


Link to post
Share on other sites
Pain

| Or. The expression on one side or the other can be matched.

Edit: The formating got screwed, a vertical line is the OR operator.

Edited by Pain

Share this post


Link to post
Share on other sites
Fulano

It's worth noting that the RegExp syntax is a bit different that you will find for grep or perl

perl/grep style:

(first|second)

AutoIt style

[first|second]

That'll cause you problems if you are converting a regexp you found online somewhere.

Good luck :mellow:


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
GEOSoft

SsStr = FileRead("some file containing the text you supplied.txt")
$aArray = StringRegExp(StringRegExpReplace($sStr, "(?i)(?s).*login\sscript.+?\v+(.+$)", "$1"), "(?i)(?m:^)(map.+|@net.+)(?:\v|\z)", 3)
If NOT @Error Then
    For $i = 0 To Ubound($aArray)
        ;; Do What you want here
    Next
EndIf


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

It's worth noting that the RegExp syntax is a bit different that you will find for grep or perl

perl/grep style:

(first|second)

AutoIt style

[first|second]

That'll cause you problems if you are converting a regexp you found online somewhere.

Good luck :mellow:

You might want to reconsider that. Using your example AutoIt will match any of the characters between "[" and "]"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Fulano

You might want to reconsider that. Using your example AutoIt will match any of the characters between "[" and "]"

Dang, you're right! Sorry about that folks, wrong language.

Edit: Realized what language was tripping me up. Got AutoIt confused with Javascript there for a moment. Sorry about the mixup. :mellow:

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
GEOSoft

Dang, you're right! Sorry about that folks, wrong language.

Edit: Realized what language was tripping me up. Got AutoIt confused with Javascript there for a moment. Sorry about the mixup. :mellow:

And therein lies the major drawback to SRE's, there are just too many flavors of it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

Geo, sometimes theres a space between @ and NET

i tried throwing in the (?x) but it doesnt seem to work..

StringRegExp(StringRegExpReplace($novell_output, "(?i)(?s).*login\sscript.+?\v+(.+$)", "$1"), "(?i)(?m:^)[b](?x)[/b](map.+|@net.+)(?:\v|\z)", 3)
Edited by gcue

Share this post


Link to post
Share on other sites
Fulano

(?x) ignores whitespace in the regex so you can make it more readable.

Try putting \s* between @ and NET


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
GEOSoft

Geo, sometimes theres a space between @ and NET

i tried throwing in the (?x) but it doesnt seem to work..

StringRegExp(StringRegExpReplace($novell_output, "(?i)(?s).*login\sscript.+?\v+(.+$)", "$1"), "(?i)(?m:^)[b](?x)[/b](map.+|@net.+)(?:\v|\z)", 3)

$aArray = StringRegExp(StringRegExpReplace($sStr, "(?i)(?s).*login\sscript.+?\v+(.+$)", "$1"), "(?i)(?m:^)(map.+|@\s*net.+)(?:\v|\z)", 3)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

got it-thanks!!!!!

ok im starting to understand this.. just the placement of things is sometimes weird

thanks for your help fellas.

Edited by gcue

Share this post


Link to post
Share on other sites
GEOSoft

got it-thanks!!!!!

ok im starting to understand this.. just the placement of things is sometimes weird

thanks for your help fellas.

Glad to help.

PM me if you want a tool for testing SRE's


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

im looking at different ones.. which one u have in mind?

Share this post


Link to post
Share on other sites
GEOSoft

im looking at different ones.. which one u have in mind?

The one I use mainly is a version by Szhlopp and wOuter and highly modified by me (constantly modified I might add). I also use Expresso on occasion but none of the ones you will find on line are AutoIt specific and often the RegExp that you test will be fine in the tester and not when used in your code.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

are there any that are autoit specific?

Share this post


Link to post
Share on other sites
GEOSoft

are there any that are autoit specific?

The one I modified. That's the one I'll send if you want it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

i tried to use the same syntax for another example but i cant figure out why its not working

Last Intruder Address:

TCP/IP Network Address

IP Address: 30.20.212.274

Maximum Connections: 6

Login Script:

map k:=lo-ncs_usrs2_server\usrs2:

@NET USE x: \\loap01\tms

Login Time: 05:09:48 am 03/11/10

modifiersName: CN=CGNDSDR1

Network Address:

TCP/IP Network Address

IP Address: 30.20.12.14

StringRegExp(StringRegExpReplace($novell_output, "(?i)(?s).*last\sintruder\saddress.+?\v+(.+$)", "$1"), "(?i)(?m:^)(ip\saddress.+)(?:\v|\z)", 3)
_ArrayDisplay($novell_last_intruder_address)

i didnt put the * after \s because it will always have a space between those instances

Edited by gcue

Share this post


Link to post
Share on other sites
GEOSoft

i tried to use the same syntax for another example but i cant figure out why its not working

StringRegExp(StringRegExpReplace($novell_output, "(?i)(?s).*last\sintruder\saddress.+?\v+(.+$)", "$1"), "(?i)(?m:^)(ip\saddress.+)(?:\v|\z)", 3)
_ArrayDisplay($novell_last_intruder_address)

i didnt put the * after \s because it will always have a space between those instances

$aArray = StringRegExp($RegExpReplace($novel_output, "(?i)(?s)Last\sIntruder.+?\v+(.+$)", "$1"), "(?i)(?m:^)(ip\saddress.+)(?:\v|\z)", 3)
_ArrayDisplay($aArray)

Works for me.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.