I would like to do the following substitution : replace $
of words located between 2 $
by the symbol # and do nothing if these words are between 2 $$
.
For example, in this text :
Currently, we are able to make cross correlations (understand "combine" to have better constraints on cosmological parameters) between weak lensing (WL) and photometric Galaxy clustering (GCph). When I say combine, as in the case where I have 2 sets of different measures ($\tau_1, \sigma_1$) and ($\tau_2, \sigma_2$), well, if I consider the Gaussian errors, it is shown quite easily (by Maximum Likelihood Estimation) that the estimator $\sigma_{\hat {\tau}}$ the most representative matches the relation:
$$\dfrac{1}{\sigma_{\hat{\tau}}^{2}}=\dfrac{1}{\sigma_1^2}+\dfrac{1}{\sigma_2^2}$$
The substitution would give :
Currently, we are able to make cross correlations (understand "combine" to have better constraints on cosmological parameters) between weak lensing (WL) and photometric Galaxy clustering (GCph). When I say combine, as in the case where I have 2 sets of different measures (#\tau_1, \sigma_1#) and (#\tau_2, \sigma_2#), well, if I consider the Gaussian errors, it is shown quite easily (by Maximum Likelihood Estimation) that the estimator #\sigma_{\hat {\tau}}# the most representative matches the relation:
$$\dfrac{1}{\sigma_{\hat{\tau}}^{2}}=\dfrac{1}{\sigma_1^2}+\dfrac{1}{\sigma_2^2}$$
I tried to perform this with the following command under vim :
%s/\$[^\$]\(.*\)\$[^\$]/#\1#/g
or
%s/\$[^\$]\(.\{-}\)\$[^\$]/#\1#/g
But this doesn't work. I can't see my error.
You may use this regex replacement in vim
using negative lookahead and negative lookbehind:
Search:
:%s/\v\$@<!\$([^$]+)\$\$@!/#\1#/g
Replacement:
#\1#
Explanation:
%s/
: Global substitution\v
: Start very magic mode instead of BRE\$@<!
: Negative lookbehind to assert that we don't have $
at previous position\$
: Match a literal $
([^$]+)
: Match 1+ of any character that is not $
and capture it in group #1\$
: Match a literal $
\$@!
: Negative lookahead to assert that we don't have $
ahead#\1#
: Replace with back-reference of group #1 surrounded with #