Demivec wrote:SFSxOI wrote:To add other specific characters in case you want to refine the alphanumeric expression just add them after the [:alnum:] and before the following bracket - for example I added a '.' to support floats with this [:alnum:].] (note the '.' after [:alnum:] but before the next bracket)
@SFSxOI: I thought the topic of the thread was about functions for determining 'IsAlpha' or 'IsNumeric', not 'IsAlphaNumeric'

.
Even though floats are numerals + symbols they don't include letters. Wouldn't that make alpha-numeric detection a bit of an overkill unless you are detecting number bases higher than ten.
I was just offering examples specific to the other more recent posts indicated using character classes and how to modify the character classe usage for special uses that can simplify regular expressions for common uses along the lines of alpha and numeric uses. For example, luis expressed for something that would do "1,0" so i offered the IsAlphaNumeric due to the thread topic, but he could have done a 'digit' class regular expression and added a ',' if all he was interested in was strings of digits with a ',' in them. However, since you bought it up, and back to straight Alpha or Numeric (and one for floats):
[:digit:] = Only the digits 0 to 9
[:alnum:] = Any alphanumeric character 0 to 9 OR A to Z or a to z.
[:alpha:] = Any alpha character A to Z or a to z.
[:blank:] = Space and TAB characters only.
[:xdigit:] = Hexadecimal notation 0-9, A-F, a-f.
[:punct:] = Punctuation symbols . , " ' ? ! ; : # $ % & ( ) * + - / < > = @ [ ] \ ^ _ { } | ~
[:print:] = Any printable character.
[:space:] = Any whitespace characters (space, tab, NL, FF, VT, CR). Many system abbreviate as \s.
[:graph:] = Exclude whitespace (SPACE, TAB). Many system abbreviate as \W.
[:upper:] = Any alpha character A to Z.
[:lower:] = Any alpha character a to z.
[:cntrl:] = Control Characters NL CR LF TAB VT FF NUL SOH STX EXT EOT ENQ ACK SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC IS1 IS2 IS3 IS4 DEL.
Code: Select all
Procedure IsNumeric(in_str.s)
rex_IsNumeric = CreateRegularExpression(#PB_Any,"^[[:digit:]]+$") ;
Is_Numeric.b = MatchRegularExpression(rex_IsNumeric, in_str)
ProcedureReturn Is_Numeric
EndProcedure
Procedure IsNumericFloat(in_str.s)
rex_IsNumericFloat = CreateRegularExpression(#PB_Any,"^[[:digit:].]+$") ; Any digit 0-9 and float
Is_NumericFloat.b = MatchRegularExpression(rex_IsNumericFloat, in_str)
ProcedureReturn Is_NumericFloat
EndProcedure
Procedure IsAlpha(in_str.s)
rex_isAlpha = CreateRegularExpression(#PB_Any,"^[[:alpha:]]+$") ; A-Z and a-z
is_Alpha.b = MatchRegularExpression(rex_isAlpha, in_str)
ProcedureReturn is_Alpha
EndProcedure
Debug IsNumeric("1234567890")
Debug IsNumericFloat("1.0")
Debug IsNumericFloat("123456901.1235")
Debug IsAlpha("ABCDabcd")
There are also abbreviations of the above as well:
\d = Match any character in the range 0 - 9 = [:digit:]
\D = Match any character NOT in the range 0 - 9 = [^[:digit:]]
\s = Match any whitespace characters (space, tab etc.) = [:space:] EXCEPT VT is not recognized
\S = Match any character NOT whitespace (space, tab) = [^[:space:]]
\w = Match any character in the range 0 - 9, A - Z and a - z = [:alnum:]
\W = Match any character NOT the range 0 - 9, A - Z and a - z = [^[:alnum:]]
Example using abbreviation:
Code: Select all
Procedure IsNumeric(in_str.s)
rex_IsNumeric = CreateRegularExpression(#PB_Any,"^\d+$") ; Any digit 0-9
Is_Numeric.b = MatchRegularExpression(rex_IsNumeric, in_str)
ProcedureReturn Is_Numeric
EndProcedure
Debug IsNumeric("123")
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.