Backref $1 is inserted as literal text during a regex find/replace


#1

During ‘find/replace’, the backref $1 is being inserted as literal text. I have the latest Atom installed, and regex is on. Tried in Latex and plain text syntax mode. Here’s my code:

typical example:  Find/Replace `some phrase' with ‘some phrase’
 `[\w ]+'
 ‘$1’

I want to replace the Latex quotes ` and ’ with unicode typographical quotes ‘ and ’. There’s an issue on GitHub relating to Atom’s Regex syntax where several uses report the same problem.


Regex in replace not working?
#2

What if you place a capture in your regexp?

`([\w ]+)'

#3

As @john indicated, you need to have a capture in the find field. From my response on the Issue:

  1. Open the atom/atom project in Atom
  2. Open the README.md file
  3. Press Cmd+F to open the find-and-replace panel
  4. Ensure that Regular Expressions mode is turned on
  5. Enter (atom.io) in the find field
  6. Enter foo$1 in the replace field
  7. Click Find
  8. Click Replace

When you do this, the found instance of the text atom.io is replaced with fooatom.io. However, if you enter atom.io without the parens in the fifth step, then the text atom.io is replaced with foo$1.

Verified this behavior using Atom v1.0.12-ad95281 on Mac OS X 10.10.5.


#4

Thanks @john and @leedohm - temporary mental blindness, completely forgot to actually ‘capture’ anything!