Simple but couldn't figure out - Contains any number

Hello - How can I find if my text contains a number or any special chars?

I have tried like:

Log mytext contains number
Log mytext contains integer
Log mytext contains digit
Log mytext contains any item of 0..9

Then finally found using the match like:
Log the occurance of <digit> in myText

Same way, would like to know if any keywords like special chars or similar? Or Do I need to list out the special chars in the pattern above?

How about using a regular expression?

Log mytext contains pattern "[^A-Za-z0-9]" -- true if text contains any non-alphanumeric chraracters
Log mytext contains pattern "[^\w]" -- true if text contains any non-alphanumeric or underscore chraracters

1 Like

Hey @scsvel,
In case you would like to use Sensetalk patterns which are regular expressions in a more “wordy” way you can.

set mytext to "Karsten11"
put mytext contains <chars in ("0".."9")>
put mytext contains <digits>
put mytext contains <nonAlphanumeric>
log every occurrence of <2 digits> in mytext --["11"]
log every occurrence of <3 letters> in mytext  --["Kar","ste"]

Cheers,
Karsten

1 Like