godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.5k stars 21.07k forks source link

RegexMatch - get start and end values of get_strings() missing #18086

Closed blurymind closed 4 years ago

blurymind commented 6 years ago

How do we get the start and end positions of matched.get_strings()[1] ...

There seems to be no method to do it :o

As a side node - it would be VERY useful if godot had a proper built in method to do regexreplace. I know it's easy to write my own, but it's so commonly used and saves so much time - I am surprised godot doesnt have it yet.

@leezh ? :)

In any case I was able to create my regexreplace function in gdscript like this:

func regexReplace(expression,inputString,replaceWith):
    var result = inputString
    var ex = RegEx.new()
    ex.compile(expression)
    for matched in ex.search_all(inputString):
        result=result.substr(0,matched.get_start()) + replaceWith + result.substr(matched.get_start()+matched.get_strings()[1].length(),result.length())
    return result

But I will be able to make it better if I could get the start and end of matched.get_strings()[1], which is missing in godot

Calinou commented 4 years ago

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!