Vim Emacs Regex Smackdown
So, I was trying to convert an orgmode file to html. There is an orgmode-export-as-html function, but it was choking on something, so I needed to do the conversion by hand. I tried many, many times to convert the file with emacs regular expressions, but was unsuccessful. The difficulty was the orgmode headlines, which look like this:I wanted to simply transform this into
The literal asterisks had to be matched with \*.
Next, to match to the end of the line I used: \(\(w*\).*\)
\( \) creates a matching group, which can be used later in the replacement string with \1 or \2 etc.
Also \(w*\).* matches 1 or more words
The % matches the entire file
The \1 matches the first matching group in the search string
That is, \1 will match everything on the line after the 3 literal asterisks.
Your matches will be highlighted. Click ‘n’ to jump to the next match.
*** Use the sort function
<h3>Use the sort function</h3>
Vim RegexpI was finally able to match the headline in vim with the following regular expression:
Vim Substitution Expression
Testing Matching StringIts easy to test a regular expression in vim. While in command mode (hit Esc if you are in input mode), type a / and then type your regular expression and then press “return”, like so: