-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
Matching at the start/end of a string doesn't work as expected; it seems that ^ and $ are not correctly honored (see
sample below under "Reproduction Steps").
The following Python code does what I intend to do:
import re
g_name = r"_#abc.#_ab#"
g_re = r"(^[#.]+)|([#.]+$)" # Replace either at the beginning or at the end of the string
print(re.sub(g_re, "*", g_name))
Correctly prints: abc.#_ab
g_re = r"^[_#.]+" # Replace only at the beginning of the string
print(re.sub(g_re, "*", g_name))
Correctly prints: *abc.#_ab#
Reproduction Steps
import regex
g_name := r"_#abc.#_ab#"
mut g_re := regex.regex_opt(r"(^[#.]+)|([#.]+$)")!
println(g_re.replace(g_name, "*"))
// Prints: _#abc.#_ab#, i.e. nothing is replaced.
g_re = regex.regex_opt(r"^[_#.]+")!
println(g_re.replace(g_name, ""))
// Prints: abcab, i.e. EVERY occurrence is replaced. What about the start-of-line anchor?
Expected Behavior
Replace correctly (cmp. the Python results).
Current Behavior
Are documented in "Reproduction Steps".
Possible Solution
Additional Information/Context
No response
V version
0.5.0 6be2fb
Environment details (OS name and version, etc.)
Windows 10.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.