Jump to content

Regular expressions


syno
 Share

Recommended Posts

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

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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...^_^

Link to comment
Share on other sites

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

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...