You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem or limitation you are having in your project
When working with regular expressions containing backslashes, you need to escape each backslash, and the readability of the regular expression is noticeably reduced.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add raw strings literals, where only the opening quote character must be escaped. You can escape the backslash, but you don't have to if it's followed by a character that doesn't match the opening quote. EDIT: Backslashes and quotes cannot be really escaped in Python r-strings, since they stay in the result. Also, escape sequences like \n and \t do not work in r-strings (they remain unchanged). This is how r-strings work in Python, and there is a proposal for f-strings.
On the other hand, if you want \\, then even in r-strings you must use \\\\ (r-strings only get rid of doubling a single \, like \d). EDIT: I was wrong, see above. Perhaps some other option would be better, such as doubling the quote to escape (as in SQL and Pascal). Or regular expression literals like in JavaScript. EDIT: Given that string literals are already Python-like in GDScript (triple quotes for multiline strings), r- and f-strings probably should be the same as in Python.
LAST EDIT: Here are the "escaping" rules in r-strings:
\" -> \" (or \' -> \' if in r'...')
\\ -> \\ (this allows you \\\")
\ -> \
Unlike regular strings, r-strings converts special sequences to themselves.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
'\\d+(?:\\.\\d+)?|\\+|-|\\*\\*?|/|\\(|\\)|(.)'
r'\d+(?:\.\d+)?|\+|-|\*\*?|/|\(|\)|(.)'
Python r-strings:
print(r'" \' \ \\') # " \' \ \\
print(r"\" ' \ \\") # \" ' \ \\
You cannot represent a string containing an even number of backslashes in a row before a quote.
Also multiline string literals (r"""string""" and r'''string''').
If this enhancement will not be used often, can it be worked around with a few lines of script?
This is about GDScript syntax.
Is there a reason why this should be core and not an add-on in the asset library?
This cannot be done with an add-on.
The text was updated successfully, but these errors were encountered:
Describe the project you are working on
Various projects.
Describe the problem or limitation you are having in your project
When working with regular expressions containing backslashes, you need to escape each backslash, and the readability of the regular expression is noticeably reduced.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add raw strings literals, where only the opening quote character must be escaped. You can escape the backslash, but you don't have to if it's followed by a character that doesn't match the opening quote. EDIT: Backslashes and quotes cannot be really escaped in Python r-strings, since they stay in the result. Also, escape sequences like
\n
and\t
do not work in r-strings (they remain unchanged). This is how r-strings work in Python, and there is a proposal for f-strings.On the other hand, if you want
\\
, then even in r-strings you must use\\\\
(r-strings only get rid of doubling a single\
, like\d
). EDIT: I was wrong, see above. Perhaps some other option would be better, such as doubling the quote to escape (as in SQL and Pascal). Or regular expression literals like in JavaScript. EDIT: Given that string literals are already Python-like in GDScript (triple quotes for multiline strings), r- and f-strings probably should be the same as in Python.LAST EDIT: Here are the "escaping" rules in r-strings:
Unlike regular strings, r-strings converts special sequences to themselves.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Also multiline string literals (
r"""string"""
andr'''string'''
).If this enhancement will not be used often, can it be worked around with a few lines of script?
This is about GDScript syntax.
Is there a reason why this should be core and not an add-on in the asset library?
This cannot be done with an add-on.
The text was updated successfully, but these errors were encountered: