Regex-based matching and sustitution with nano?



I am aware of nano‘s search and replace functionality, but is it capable of using regular expressions for matching and substitution (particularly substitutions that use a part of the match)? If so, can you provide some examples of the syntax used (both for matching and replacing)?

I cut my teeth on Perl-style regular expressions, but I’ve found that text editors will sometimes come up with their own syntax.


You need to add, or un-comment, the following entry in your global nanorc file (on my machine, it was /etc/nanorc):

set regexp

Then fire up a new terminal and press CTRL + / and do your replacements which should now be regex-aware.


Search for conf->(\S+):

enter image description here

Replace with \1_conf

enter image description here

Press a to replace all occurrences:

enter image description here

End result:

enter image description here

Answered By – Bart Kiers

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More