Jump to content

Format of a string


Terenz
 Share

Recommended Posts

How i can know if a string has a predefinite "rule"?

Example i have a string with 2 numbers, a slash, 3 numbers, a space, 2 letters, a slash, 3 letters

So i'd like to know if a string follow this rule.

Thanks :D

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

Terenz,

You will need to use a "Reguar Expression" - the AutoIt function you need to use is StringRegExp. In this case you would need a pattern like:

 

d{2}d{3}sw{2}w{3}

And as it seems you have not had the pleasure of using these little buggers before, be prepared for your brain to begin bleeding as you get to grips with them. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yes is my first time with regular expression, i'll check your example and the help for StringRegExp but seems a little complicated :D

If i have some doubt i'll post here.

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Use a regexp:

$string1 = "11/123 aS/asa" ; will pass
$string2 = "1a/123 as/asa" ; will not pass
$regexp = "\d{2,2}/\d{3,3}\s[A-z]{2,2}/[A-z]{3,3}"

$return1 = CheckStringFormat($string1, $regexp)
$return2 = CheckStringFormat($string2, $regexp)
ConsoleWrite($return1 & @CRLF)
ConsoleWrite($return2 & @CRLF)

Exit

Func CheckStringFormat($sString,$sRegExp)
    Local $bReturn = False
    If StringRegExp($sString,$sRegExp,0) Then $bReturn = True
    Return $bReturn
EndFunc
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Try it out, there is no diference.  One states the min, and max count (since they are the same number, it's redundant), the other shows the expected count.

Don't use the w, though.  That will return alpha and num chars (also _ ). [A-z] will return only alpha chars.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Moderators

Terenz,

My version is shorthand for jdelaney's - both say "exactly that number". ;)

I always point people to this site to begin to learn about RegExes. I am afraid they are far too big a subject to cover in a thread like this, even if I felt remotely qualified to do so. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I know both work but i have just try to understand why use two different method ( {2} and {2,2} ) for the same numeric string, there are different approach and i think this is not good for a regex noob like me :D

Yes [A-z] fit well my string

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

http://gskinner.com/RegExr/

I've blabbed about it before, probably will again. this site is AMAZING for regular expression testing and creation. You can mouseover symbols at the top and it will tell you what they mean, it will show you groups, what it matches, what it returns. It even has a list of bits and peices in the right hand side that;s amazingly useful. RegExp is standardizes so you can copy paste that into autoit's stringregexp() function.

Tips: mode 3 for stringregexp() will return all the results as an array, and adding (?i) in front of the pattern makes it case insensitive. Happy Regexing :D

Edit: I also recently learned that when you have a set, say d, you can follow it by {2,6} to match between 2 and 6 times :D 

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

corgano,

The site you recommend may be pretty but it doesn't implement the same regular expression flavor as AutoIt uses (namely: PCRE).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

corgano,

The site you recommend may be pretty but it doesn't implement the same regular expression flavor as AutoIt uses (namely: PCRE).

Can you give me an example? Everything I have had in there works in autoit, with the exception of the in-string flags which are different

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

More precisely, actionscript uses ECMA specifications but AutoIt uses the PCRE engine.

Hex input syntax differ. ECMA doesn't support Unicode character properties (AutoIt beta and next release will), subroutines, conditionals, recursion, ...

There are too many important differences to list exhaustively.

So yes this tool will deliver the same results as AutoIt for the simplest patterns but will turn in turmoil for general use.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks for the info! It's been good enough for me so far, I thought other people might find it useful when they start out with regexp. I like how simple it is.

So ECMA is older / less advanced than PCRE? that would mean things in regexr will work in autoit but autoit patterns might not work in regexr right? Do you know of a similar tool that supports all of the PCRE regex features? 

I found this one but It's a bit more complicated to use. Nice diagrams though :D

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

ECMA and PCRE are simply not fully compatible.

There are some available on this forum and a good link in my signature (pcretest for instance).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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