Valid Regex not working?

Godot Version

4.5

Question

So, I made the following regex string:
(class [a-z]*? inherits [a-z]*?|(override|class) [a-z]*?) {([^]]*?), and tested it on regex101.com, using the same regex engine as godot (PCRE2), and I works fine.
However, when I put it into godot, it gives the error Condition "!is_valid()" is true. Returning: nullptr, upon using search_all()

Does anyone know what could be going on here ?

Try compiling with show_error = true and see if it throws and error

I get no errors thrown from that (except from the ones already mentioned)

That wouldn’t happen, if it doesn’t print any errors on compile it would be valid, try:

var my_regex := Regex.new()
if my_regex.compile(your_expression, true) != OK:
    print("Error!")
    return

or

var my_regex := Regex.create_from_string(your_expression, true)
if not my_regex or not my_regex.is_valid():
    print("Error!")
    return

And then search after

I am truly the dumbest person alive. I accicentaly compile the regex after it was needed to be used. Sorry for a colossal waste of time.

1 Like

With respect, if you think that small mistake qualifies you as the dumbest person alive you need to pay more attention to other people.

Personally, the mistake you made wouldn’t even crack the top ten list of mistakes I have made writing code.

2 Likes