From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 81EED1F461 for ; Sat, 17 Aug 2019 18:30:40 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8F69A120970; Sun, 18 Aug 2019 03:30:22 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 6809F120970 for ; Sun, 18 Aug 2019 03:30:14 +0900 (JST) Received: by filter0059p3las1.sendgrid.net with SMTP id filter0059p3las1-2811-5D5847B8-6F 2019-08-17 18:30:16.948830902 +0000 UTC m=+1717.934861631 Received: from herokuapp.com (unknown [52.91.241.246]) by ismtpd0007p1iad2.sendgrid.net (SG) with ESMTP id 2iStvP-bS4mrDYukFD2IKQ for ; Sat, 17 Aug 2019 18:30:16.862 +0000 (UTC) Date: Sat, 17 Aug 2019 18:30:17 +0000 (UTC) From: vivian.unger@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69950 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16108 X-Redmine-Issue-Author: VivianUnger X-Redmine-Sender: VivianUnger X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?L82NdsNoQxJpar0e+TwfC3YJAZMS9SSfBZ9=2FmwScDU+iQi7+Uc888ATEIT8=2Fik?= =?us-ascii?Q?ph0CDZZuW4hf3E0eohXSbdD7EkRosxfJEceS6JW?= =?us-ascii?Q?HOM8KaWUyGPA8gpvtwF1nnULati0Op0Sw4zuFOS?= =?us-ascii?Q?AqVZ3SwK9kklB=2F8mQf23fmYVPAHn9Pw6vxHNqCE?= =?us-ascii?Q?=2FOsVsJVR3Z66kkR0tzCjDYKh6LZkSDQYeMg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94402 Subject: [ruby-core:94402] [Ruby master Bug#16108] gsub gives wrong results with regex backreferencing and triple backslash X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16108 has been reported by VivianUnger (Vivian Unger). ---------------------------------------- Bug #16108: gsub gives wrong results with regex backreferencing and triple backslash https://bugs.ruby-lang.org/issues/16108 * Author: VivianUnger (Vivian Unger) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- I have written a script to convert LaTeX indexing files (.idx) to Macrex backup format (.mbk), so that I can import LaTeX-embedded indexes into the Macrex indexing program. A problem arises when I try to convert bolded text. LaTeX indicates bolded text with the tag \textbf{} while Macrex wraps it in backslashes: \\. In my test case, the input string is "\indexentry{\textbf{bold}|hyperpage}{2}", which I need to convert into "\indexentry{\bold\|hyperpage}{2}". For this I am using: record.gsub(/\\textbf\{([^\}]+)\}/, '\\\1\\') But instead of the expected output, I get: \indexentry{\1\|hyperpage}{2} ...as if I only had \\ rather than \\\. I have tried the same Regex in a search-and-replace in Notepad++ and it works as expected. It's only in Ruby that I get this unexpected result. The kludgey workaround I have found is to leave a space before the \\: record.gsub(/\\textbf\{([^\}]+)\}/, '\\ \1\\') ...giving the result: \indexentry{\ bold\|hyperpage}{2} But this won't do. Macrex complains and the extra space has to be edited out. Imagine if you have hundreds of lines with bold text in them! -- https://bugs.ruby-lang.org/