GNOME Bugzilla – Bug 515944
Double replace
Last modified: 2008-02-17 14:09:03 UTC
Please describe the problem: String was double replaced Steps to reproduce: #include <glib.h> int main() { GRegex *regex = g_regex_new ("(?=[A-Z0-9])", 0, 0, NULL); g_printf("%s", g_regex_replace_literal (regex, "RegExTest", -1, 1, "_", 0, NULL)); } Actual results: Reg__Ex__Test Expected results: Reg_Ex_Test Does this happen every time? Yes Other information:
The expected result should be '_Reg_Ex_Test', in Python you get: >>> import re >>> re.sub('(?=[A-Z0-9])', '_', 'RegExTest') '_Reg_Ex_Test' I'm going to try to fix the bug in the next days, for now you can use a workaround (to get 'Reg_Ex_Test', not '_Reg_Ex_Test': #include <glib.h> int main() { GRegex *regex = g_regex_new ("(.)(?=[A-Z0-9])", 0, 0, NULL); g_printf("%s", g_regex_replace (regex, "RegExTest", -1, 1, "\\1_", 0, NULL)); }
(In reply to comment #1) > The expected result should be '_Reg_Ex_Test', in Python you get: > >>> import re > >>> re.sub('(?=[A-Z0-9])', '_', 'RegExTest') > '_Reg_Ex_Test' > > I'm going to try to fix the bug in the next days, for now you can use a > workaround (to get 'Reg_Ex_Test', not '_Reg_Ex_Test': > You misunderstend me: 1. Starting position is *1* (not *0*) so there is no leading '_'. Both in expected as in actual result. 2. It inserts double '_' 3. Your code results in 'Re_E_Test'
Sorry, didn't see the 1. Here my code works with glib 2.14.6 and PCRE 7.6, I will try with glib 2.15 later.
In perl all is ok. My glib version is 2.15.4
2008-02-17 Marco Barisione <marco@barisione.org> * glib/gregex.c: (match_info_new), (g_match_info_next): Don't return duplicate matches when matching empty strings. (#515944) * tests/regex-test.c: Add tests.