Sublime Forum

Regexp in find replace - find (A) (B) where (B=A)

#1

Hello, good evening all!
I have some text with two words per line like
- abc - def -
- ghi - ghi -

I want to select the line where the two words are equal: here, ghi
In, for instance, python re, I would use something like

re.sub(r'\- (?P<stem>[a-z]+ \- (?P=stem) \-', ...)

But I can’t use this syntax in Sublime Text’s find/replace :slight_smile:I get the message “invalid or unterminated PERL sequence”

Is there another way to do it ?
Thanks !

0 Likes

#2

The following should work

\- ([a-z]+) \- \1 \-
1 Like

#3

it does work, thanks a lot !!!

0 Likes

#4

in case you want to keep the named capture groups:

- (?<stem>[a-z]+) - \g<stem> -
1 Like