A regular expression is an advanced search syntax for finding text. It is wholly ignorant of things like formatting. You can’t search for italics with it, that is what LibreOffice is for. If you’ve ever used a search engine (such as the one on this forum) that lets you search for things like “compil*”, then you know the asterisk means: look for the string of letters ‘compil’ and let there also be matches that may have more letters after it, like ‘compiler’, ‘compile’ or ‘compiling’. Regular expressions are that concept on steroids.
For \1 to work, you need to store some search material into that token. And we do this by searching for stuff, and wrapping the part we want to store into \1, with parentheses. Here is a very simple example:
Libre(Office)
Now if we replace that with the following, we will get “OpenOffice”:
Open\1
The \1 recalls the stuff inside the parentheses and prints it as part of the replacement. You could search for “(last name), (first name)” and flip the order with “\2 \1”. Hopefully that all makes sense.
So what you want to do is find anything that is italic, and this is where the asterisk trick before, or the wildcard, comes into play. RegEx is full of wildcards, and variations on wildcards, and ways to use wildcards that even confuse programmers, but fortunately we just need a simple one. Since we don’t care what actual text we are finding is, and just care if it is italic, we can use a universal wildcard and specify that we don’t care how many letters and spaces and numbers and symbols we get, just so long as they are italic:
code
[/code]
The ‘.’ in regular expressions means any character, it’s a bit like the asterisk in simpler search syntaxes, but only one character. Absolutely anything, even stuff you can’t see, like tabs and spaces will qualify as a ‘.’. The ‘+’ is a quantifier, or how many of those we want. It means one or more of whatever falls before it, so in this case we want one or more characters of any kind that are italic. You’ll recognise that we then wrap it in parentheses to store what we capture into \1.
Now, you can put whatever you want around it in the replacement field, like so:
{{\1}}
In this sample paragraph, if we ran that search and replace, we would get:
In {{this sample paragraph}}, if we ran that search and replace…