Jump to content
Sign in to follow this  
syno

Regular expressions

Recommended Posts

syno

Hi guys

I have been doing some work with regular expressions and the autoit help file, but I have run into a bit of a conundrum!!! I have managed to match a single string exactly. This works for letters and numbers, the regular expression is shown below:

MsgBox(0, "TEST A STRING!", StringRegExp("findme2", '\A\bfindme2\b\z'))

However, I now want to match 'findme2: '

So the regular expression is also to match ':' and a single whitespace (carriage return) at the end of the string. Is this possible?

Thank you

Share this post


Link to post
Share on other sites
Mat

MsgBox(48, "Test", StringRegExp("findme2:" & @CRLF, "\bfindme2:\s"))
??

or did you want either?

MsgBox(48, "Test", StringRegExp("findme2:" & @CRLF, "\bfindme2:\s|\A\bfindme2\b\z"))
?? Edited by mdiesel

Share this post


Link to post
Share on other sites
syno

Hi there,

This line would be great!

MsgBox(48, "Test", StringRegExp("findme2: " & @CRLF, "\bfindme2:\s|\A\bfindme2\b\z"))

If the '|' (OR) part of it was an AND instead. Is this possible??? You see it has to satisfy both of these conditions, not one or the other....

Share this post


Link to post
Share on other sites
Mat

by satisfying "findme:" it has to satisfy "findme"... as "findme" is within the "findme:"...

I don't quite understand what you are trying to do here, so I'm stabbing in the pitch black.

If StringRegExp("findme2:" & @CRLF, "\bfindme2:\s") And StringRegExp("findme2:" & @CRLF, "\bfindme2\b") Then
   MsgBox (48, "Test", "Both cases matched.")
EndIf

this is a simple method, as I am not an expert with stringregexp. there is almost certainly a way to do this within one function, but I dont understand if there is digits between the matches or not.

give an example of the full string to search and the result you want and then we can see what the middle bit should be!

MDiesel

Share this post


Link to post
Share on other sites
syno

Hi mate

I just want to match 'findme2: ' and nothing else. What I have will match 'findme2'. We can forget about the whitespace for now, as I can look about this another time and it is not that important anyway. My real problem is ':' because the \b looking for the end of word boundary only picks up letters and numbers and not special characters. So the code below does not work:

MsgBox(48, "Test", StringRegExp("findme2:", "\A\bfindme2:\b\z"))

As were the following does work correctly:

MsgBox(48, "Test", StringRegExp("findme2", "\A\bfindme2\b\z"))

So the following strings I do not want a match on:

ffindme2

findme22

f findme2 2

Edited by syno

Share this post


Link to post
Share on other sites
syno

Hi

I think I have found it....What I needed was:

MsgBox(0, "Test!", StringRegExp("findme2: ", '\A\bfindme:\s\z'))

Thanks for all your help. I probably would not have got there on my own...^_^

Share this post


Link to post
Share on other sites
dantay9

If you are having trouble with stringregexp() then you should try Expresso.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
Mat

If you are having trouble with stringregexp() then you should try Expresso.

someone wrote an online RegExp tester too... haven't seen it for a while though...

This is definitely a very useful area, but its very hard to learn, it took me a lot of testing, and I still don't understand all of it, but I use it frequently as it has many advantages over stringsplit etc.

my only criticism is that it returns an array when you flag <> 0. that is something I've had to bypass many a time, and it gets a bit annowing - any devs want to add a flag??

flag = 5 >> returns the first matched string.

good to see it working

MDiesel

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.