jcubic
jcubic

Reputation: 66490

How to match this string using regex in emacs?

I've try to replace this <?= T_('XXX'); ?> for this {{ T_('XXX') }}, I've try this

<\\?= \\([^\\?]+\\) *\\?> -> {{ $1 }}

and can't make it work. What regex and replacement should I use.

PS: is there online Regex tool for Emacs, there is lot of tools out there but I can't find one for emacs (maybe there is tool in emacs itself).

Upvotes: 0

Views: 76

Answers (2)

Andreas R&#246;hler
Andreas R&#246;hler

Reputation: 4804

IIUC you don't need a regexp, a simple string replace will do it:

M-x query-replace RET
<?=
RET
{{

and then

M-x query-replace RET
; ?>
RET
 }}

Upvotes: 0

abo-abo
abo-abo

Reputation: 20342

This code will do the replacement, point has to be at buffer start:

(replace-regexp "<\\?=\\([^;]+\\); \\?>"
                "{{\\1 }}")

Interactively it's M-x replace-regexp, but each two backslashes from above you have to replace with just one.

Upvotes: 1

Related Questions