0 votes

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?

Godot version 3.2.3
in Engine

## 2 Answers

0 votes
Best answer

https://docs.godotengine.org/en/stable/classes/class_regex.html

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

by (6,280 points)
selected by

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

0 votes

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" )
``````
by (1,110 points)

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)
``````