# Random beginner-question: detect if a number between 1 and 9 is in a label

Attention Topic was automatically imported from the old Question2Answer platform.

Hi everyone,

I have a label I can enter numbers into and I can detect if single numbers are in the text with (for each number respectively):

``````var oneIsWritten = false

var one = bbcode_text.find("1")
if one >= 1:
oneIsWritten = true
print ("There's a 1 in the text!")
``````

(I can go the same way for “`there's no 1 in the text`” with "`if one <= 0:` …)

Now, if I’d like to know if there is actually any number between 1 and 9 written (explicitly leaving the 0 out), doing this with all the numbers true/false on their own would be too much handywork. I’m sure there is an elegant way of achieving this (maybe with an array…?)

What could a code for this look like?

You can use \d to match a digit and [1-9] to not match 0

I guess yes, that’s it, thank you! …so many things to learn ; )

pferft | 2021-03-30 15:13

Or You can use string operands :

``````for x in range(1,9) :
iff bbcode_text.find(str(x)) :
print ( "There is " + str(x) + " in the text" )
``````

Thank you, so for 1 to 9 I’d need `for x in range(1,10):` then, I see.
It appears that in this case I always get nine line printed, one for each number, no matter which number I enter…

For getting the info if there is actually any number written or not, NatureSilver5401 on reddit suggests:

``````var writtennumbers = Array()
writtennumbers.append("whatever you like")
for number in 9:
if str(number+1) in text:
print("There is a " + str(number+1) + " in the text"
writtennumbers.append(true)
else:
writtennumbers.append(false)
``````

pferft | 2021-03-30 19:37