Advanced Tips for Search-and-Replace in Linux - page 2
Search and Replace Power Tools
Sometimes it can be useful to use a complemented character set. This is like a range, except that what you match is any character except the ones in the range. So [^aieou] would match any character except the five vowels. One use of this might be to find quoted sentences (e.g. "this quoted sentence") in a piece of text. In Vim, use this:
/"[^"]\+"Note that this is just a search, not a search-and-replace, so you just use / at the start of it. In Emacs, use:
C-M-s "[^"]+"(The long version of C-M-s is M-x isearch-forward-regexp). This pattern looks for the " character, followed by at least one of any character except the quote character ([^"]\+, or [^"]+ in Emacs where you don't need to escape the +), followed by a final quote character.
/"[^"]\+[\n]*[^"]\+"To match three-line quotes, you'd need to add the "zero or more newlines plus one or more non-quote characters" part of this pattern another time before the closing quote.
This is just a quick guide to a couple of useful things you can do with regular expressions: the scope is immense. It's well worth spending a little time getting to grips with them, and it can be quite good fun. Have a go yourself, and soon you too will be familiar with leaning toothpick syndrome (\/\/\/\)!
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: Alienware, KDE and Ubuntu 13.04
- 2Linux Top 3: Linux Mint Olivia, Fedora 19's Cat and Ubuntu's Mission Accomplished Moment
- 3GNOME 3.8 Debuts New Open Source Linux Desktop
- 4Linux Top 3: Linux 3.10 Goes Long, Linux 3.11 Advances as LXDE Merges
- 5Linux Top 3: Ubuntu Kaylin, Debian Wheezy and Linux Mint