Sign in to follow this  
Followers 0
Uten

Stringregexp: Match End Of Line And Start Of Line

5 posts in this topic

I'm having trouble matching patterns specified to one line. This sample code is rather specific and I can extract the lines by using some of the other words, but that is not the point. I want to understand how I can write my pattern to match something starting on a line and ending on the same line.

#include <Array.au3>
; Sample found in nutsters RegExp_Test_4.au3
if not StringRegExp("Theee  always was work.", "^The*\s+\w+ was \w+[.]$", 0 ) then 
   msgbox(16, "ERROR:","StringRegExp: Faield")
   Exit
endif
; === My code =====================
$data = "This is a expected test line" & @CRLF & _
   "And This is Not a expected line" & @CRLF & _
   "This is the second expected msg" & @CRLF & _
   "This is not wanted"
$regexp ="(^This.*$)"
$arr = StringRegExp($data, $regexp,3)
ConsoleWrite("@error:=" & @error & ", @extended:=" & @extended & " , Ubound($arr):=" & UBound($arr) & @CRLF)
_ArrayDisplay($arr, "MSG")
ConsoleWrite("EXIT")

According to nutster ^ and $ was planed to be documented but I can't find it in the help file v3.1.1.118(beta)

That is how it is supposed to work. As I said, I will look into this when my computer is working again, later this week.

I am sure that I put ^ and $ in the documentation. I will look at this too.

And in this post. ^ and $ should work, but does it when you want to get the matches in an array?

Hello,

You could use RegExp but I agree that the syntax is a little hard.

To explain the Good Syntax

^T String begins with T

.* one and more char

\. the char "."

t

. one char

t

$ End of the string

HTH,

Francis

#include <Misc.au3>
$MyFile = "Test.txt"
$Good   = "^T.*\.t.t$"
$NotGood= "^A.*\.t.t$"

; First test 
Msgbox( 1 , " ", _iif(StringRegExp( $MyFile , $Good )," = " ," != " ))
; Second
Msgbox( 1 , " ", _iif(StringRegExp( $MyFile , $NotGood )," = " ," != " ))

Share this post


Link to post
Share on other sites



Sorry to dredge this thread back up... but anyone know if this is going to be implemented?


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Sorry to dredge this thread back up... but anyone know if this is going to be implemented?

@neogia has explained it very well in his stringregex tutorial thread. As it turns out the Regex implementation in AutoIt treats everything passed to the function as "one string" (including @LF, @CR and @CRLF). So someone used to sed or awk will kind of have to turn and twist his head a bit to get it right :) So if you want it (by lines) to behave as sed or awk (perl) you have to splitt the data into strings delimited by @CRLF (Or @LF, @CR) and then pass each string on to the StringRegEx function.

Share this post


Link to post
Share on other sites

Thanks for the reply Uten. The splitting the strings by @CRLF and feeding them to the stringreg will work fine then.

-Sim


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

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  
Followers 0