Jump to content

Recommended Posts

Posted
$time = "23:20:23"

$hey = StringRegExp($time, '(\w:\w:\w)')

If $hey == 1 Then
   Send("Yes")
EndIf

If $hey == 0 Then
   Send("No")
EndIf

 

So i wanna know if my string has any numbers. To do that i used StringRegExp in order to check if the string was containing any numbers.

So simply i want it to read like this: Any:Any:Any including the ":" but it always returns 0 as a "no match" which must mean that this script doesnt work. Any suggestions?

  • Moderators
Posted

Sfikes,

Try this:

#include <MsgBoxConstants.au3>

$time = "23:20:23"

$hey = StringRegExp($time, '(\d+:\d+:\d+)')

If $hey = 1 Then
   MsgBox($MB_SYSTEMMODAL, "Result", "Yes")
   Else
   MsgBox($MB_SYSTEMMODAL, "Result", "No")
EndIf

The difference is that I am looking for at least one digit in section - you were looking for only a single digit, letter or underscore.

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:

  Reveal hidden contents

 

  • Moderators
Posted

Sfikes,

Reading the Help file page for StringRegExp will explain most of the possible parameters. In this case I used:

  Quote

\d  -  Matches any decimal digit

Expand  

in conjunction with:

  Quote
+   -  1 or more
Expand  

So it will match if we have 3 groups of one or more digits separated by colons.

To be really precise, we should really ask for groups of one or two digits which comes out as:

$hey = StringRegExp($time, '(\d{1,2}:\d{1,2}:\d{1,2})')

Try it with various strings and see how it performs.

RegExes are quite tricky to learn (my brain still bleeds when developing a complex pattern) but are well worth the effort - I always recommend this site as a good place to start.

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:

  Reveal hidden contents

 

Posted
  On 10/6/2016 at 7:00 PM, Melba23 said:

Sfikes,

Try this:

#include <MsgBoxConstants.au3>

$time = "23:20:23"

$hey = StringRegExp($time, '(\d+:\d+:\d+)')

If $hey = 1 Then
   MsgBox($MB_SYSTEMMODAL, "Result", "Yes")
   Else
   MsgBox($MB_SYSTEMMODAL, "Result", "No")
EndIf

The difference is that I am looking for at least one digit in section - you were looking for only a single digit, letter or underscore.

M23

Expand  

I never understood (or invested not enough time) StringRegExp. I just tested your eample with a fantasy time:

$time = "239:204:23"

and i got also yes.

  • Moderators
Posted

Sfikes,

Delighted I could help.

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:

  Reveal hidden contents

 

Posted

In the future, these sites may help you with RegEx as they certainly helped me

http://regexr.com/ - A playground for making RegEx

https://regex101.com/-  Another playground for making RegEx

https://txt2re.com/ - Visually see and extract the data you want

http://regex.inginf.units.it/ - Builds a RegEx based on examples you provide

https://regexone.com/ - Learn RegEx

Note: These sites are not made for specifically for AutoIt coding, but it's much easier than hitting F5 a dozen times to get what you want.

  • Moderators
Posted (edited)

AutoBert,

Look at the other pattern I posted - that is more precise and only accepts one or two digits per group.

M23

Edited by Melba23
Typo

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:

  Reveal hidden contents

 

Posted

Just a note about the good links provided above: favor regex101.com as it offers the same regexp flavor as Autoit (PCRE). The reference documentation for PCRE implemented in AutoIt is http://www.pcre.org/original/doc/html/ (AutoIt doesn't implement PCRE2, yet).

  Reveal hidden contents

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)

Posted
  On 10/6/2016 at 6:49 PM, Sfikes said:

So i wanna know if my string has any numbers.

Expand  
$time = "23:20:23"
;~ $time = "ElevenTwenty"

msgbox(0, '' , AscW(stringleft($time , 1)) > 47 AND AscW(stringleft($time , 1)) < 58  ? "Yup" : "Nope")

 

  Reveal hidden contents

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...