139

I want to search and replace this

`https://example.com/`{.uri}

to

[https://example.com/](https://example.com/)

With vim I would do a s/(http.*){.uri}/[\1](\1)/g but that doesn't work with atom.io. How can I solve this?

method
  • 782
  • 4
  • 10
wintermeyer
  • 8,178
  • 8
  • 39
  • 85

2 Answers2

226

If you Cmd-F and open the search pane, there is a ".*" button at the right side. Click it and now it's regex mode.

I find

(http.*)\{\.uri\}

and replace to

[$1]($1)
wintermeyer
  • 8,178
  • 8
  • 39
  • 85
speedogoo
  • 2,828
  • 2
  • 17
  • 19
  • 4
    `s/(http.*){.uri}/[\1](\1)/g` doesn't work in `atom` with RegEx activated. Maybe it is a bug or a different RegEx syntax. That was the reason of my question. – wintermeyer Mar 13 '14 at 09:28
  • 19
    I find "(http.*)\{\.uri\}" and replace to "[$1]($1)". It works. This is the perl-style regex, which I believe is the standard. – speedogoo Mar 14 '14 at 15:15
  • 1
    @speedogoo You should submit this as the correct answer. – method Sep 05 '14 at 13:00
  • 3
    Any idea how do I eval the captured group to do some stuff on it before replacing? For example, if `$1` captures a number group - 123, replace it by adding 1 to it, something like `eval($1+1)`..? – SexyBeast Feb 22 '15 at 00:35
  • 1
    Using dollar for back referencing doesn't work for me. Is it still accurate ? I'm using atom v0.205.0 and find-and-replace package in version 0.170.0. – Antoine Jun 04 '15 at 09:29
  • 7
    Ok I just forgot to use parentheses in the regex. Just ignore what I said. – Antoine Jun 04 '15 at 11:54
  • To reproduce a find functionality similar to Sublime Text: Type `command` + `F`, type in your search, and then hit (on a Mac) `option` + `return`. If the Find All option is selected, this will create multiple cursors you that allow you to edit the search matches directly. – Greenstick Jun 12 '19 at 21:37
20

Juste to update @speedogoo's answer for future readers, if you do not find the regex mode in the search view, it looks like this:

enter image description here

You can also open it with the shortcut Ctrl+Alt+/ (default).


Note that even ^ and $ are already supported by Atom's find-and-replace.

plesatejvlk
  • 427
  • 6
  • 15
Mistalis
  • 17,793
  • 13
  • 73
  • 97