Skip to content

Instantly share code, notes, and snippets.

@mrbongiolo
Last active August 29, 2015 14:14
Show Gist options
  • Save mrbongiolo/ec122e3d4c1d4425165b to your computer and use it in GitHub Desktop.
Save mrbongiolo/ec122e3d4c1d4425165b to your computer and use it in GitHub Desktop.
Using REGEX to find and replace text on Sublime Text 3

Example 'find what' regex: url\(['"]*(?<url>[^<%|^'<%|^"<%].*?[^'"])['"]*\)
Example 'replace with' regex: url("<%= asset_path '$+{url}' %>")

I used this regex to find url('path/my_image_file.png') and convert it to url("<%= asset_path 'path/my_image_file.png' %>").

Tips:

(?<named>expression) is a named subexpression, and it can be accessed on the 'replace with' field using: $+{named}.

Sublime uses the Perl REGEX engine.

You can find more information here: http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html and here: http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/format/perl_format.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment