E1M1

How to check if string is also number?

10 posts in this topic

IsNumber fails if number is formatted as string ($nr = "1234") So I need to do it other way. I cant figure out how to do it with stringregexp.

Both returns me 0.

StringRegExp("432","{0,9}")

StringRegExp("432","[:digit:]")

edited

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

StringIsDigit

for stringregexp i dono

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Your regular expressions are broken because they check if the string is ONE character between 0-9. Simply repeat with * and it will work. Although I should note that the syntax is not {0,9} but [0-9]... :)

MsgBox(0, "", StringRegExp("432","[0-9]*"))

Share this post


Link to post
Share on other sites

Thanks.


edited

Share this post


Link to post
Share on other sites

It is not accurate.

Even the below expression is giving 1.

MsgBox(0, "", StringRegExp("g432.9h","[0-9]*"))

and

MsgBox(0, "", StringRegExp("hh","[0-9]*"))

Share this post


Link to post
Share on other sites

It is not accurate.

Even the below expression is giving 1.

MsgBox(0, "", StringRegExp("g432.9h","[0-9]*"))

and

MsgBox(0, "", StringRegExp("hh","[0-9]*"))

Share this post


Link to post
Share on other sites

StringIsDigit is giving only for integers but not for decimal values.

MsgBox(0, "", StringIsDigit("123.89"))

Returning 0.

MsgBox(0, "", StringIsDigit("123"))

Returning 1

Share this post


Link to post
Share on other sites

StringIsFloat will return True, so you can use both StringIsFloat  and StringIsDigit :

$string = "1234.45"
MsgBox(0, "", StringIsDigit($string) OR StringIsFloat($string) )

For a regex :

$string = "1234.45"
MsgBox(0, "", StringRegExp($string, "^\d+(?:\.\d+)?$" ) )

 

Share this post


Link to post
Share on other sites

Ahem, this still needs work: a number may be signed (+ or -), have no leading digit before the decimal point (e.g. .5) and then this regexp doesn't cope with reals in exp form, e.g. +123.45E-6


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)

Share this post


Link to post
Share on other sites

Yes, you're right, but maybe it's enough for what the OP asks.

This one should work :

$string = "+.23E-22"

MsgBox(0, "", StringRegExp($string, "(?i)^[+-]?(?:\d+\.?(?:\d+(?:e[+-]?\d+)?)?|\.?(?:\d+(?:e[+-]?\d+)?))$" ) )

Or this way should work :

$string = "+.23E-22"
MsgBox(0, "", Execute($string) <> "" ) ; !!! returns True for an expression like "1 + 2"

 

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