RegEx dont work correctly

Version

Godot Engine v4.2.1.stable.official.b09f793f5

Question

I’m making my compiler for GLM (Godot mod Language) and I’m having some difficulties with regex:
/(\\w+)\\(((?:[^)(\\\"]|\\\\\\(|\\\\\\\\)*?)\\)(?![^\"]*\"\\s\\))(\\.(.+?)\\(((?:[^)(\\\"]|\\\\\\(|\\\\\\\\)*?)\\))?/

This regex stands as var funcRegex and I’m using it here:

func comp_func(code):
	var expr = Expression.new()
	var regex = RegEx.new()
	regex.compile(funcRegex)
	for func_result in regex.search_all(code):
...

In the code variable I pass: create(Button,btn_ru).handler(command=btnClick)
It should grab it, but for some reason it doesn’t. I tried outputting get_pattern() and testing it on regex101.com:
/(\w+)\(((?:[^)(\"]|\\\(|\\\\)*?)\)(?![^"]*"\s\))(\.(.+?)\(((?:[^)(\"]|\\\(|\\\\)*?)\))?/

But I don’t have anything in my godot.

The function is called, the code is produced correctly (without spaces and all that) and godot does not complain about anything (even in the console). The only thing that can be confusing is that the regex itself is built in such a way that it captures functions only if there is no ") " (closed bracket with a space) before them.

Remove the starting and final / in your regex pattern.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.