Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex Replace does not use captured groups #656

Open
sweBers opened this issue Sep 7, 2024 · 1 comment
Open

Regex Replace does not use captured groups #656

sweBers opened this issue Sep 7, 2024 · 1 comment

Comments

@sweBers
Copy link

sweBers commented Sep 7, 2024

 * Xed version 3.4.5
 * Distribution - Linux Mint 21.3 Cinnamon

Issue
Regex replace does not use captured groups ()

Steps to reproduce
Select Search and replace from the menu with multiline text
Search for a regex pattern with a subgroup i.e abc(123) with the text aabc1234
Attempt to use the captured pattern with the variable $1 in the replace

Expected behaviour
The variable $1 will be expressed as the captured text 123
Instead, the replacement text will feature $1 as the literal replacement text

Other information

@zpangwin
Copy link

zpangwin commented Dec 3, 2024

Capture groups work, but for back-references, Xed uses \1 etc instead of $1 (this is also common in many terminal apps like sed). Disclaimer: Though I don't believe there should be any difference, I am testing from Fedora Cinnamon instead of on Mint. I am using Xed 3.4.5

Examples (with ".*" regex button enabled obviously):

text content:

quick red fox jumped over fence

search pattern:

(quick|fence)

replace pattern:

the \1

text after hitting 'replace all' button:

the quick red fox jumped over the fence

OR

text content:

the quick red fox jumped over the fence and fell flat on its face

search pattern using capture group + back reference

(the) quick.*\1 fence

will correctly highlight as follows:

the quick red fox jumped over the fence


Possibly the ticket could be changed to "Request Xed support both \1 and $1 style backreferences" when using capture groups (similar to perl / prename and some other apps).

That would probably avoid confusion for people who are only familiar with the Perl/Java/JavaScript variants of Regex (which are actually a lot more common these days) while not really disrupting folks used to the Posix-style back references much except possibly forcing them to escape dollar signs in the replace expression.

Or alternately, could possibly be user-configurable which style back-references Xed should use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants