Felix
Felix

Reputation: 2661

Notepad++ - Find and replace both opening and closing tags while keeping the content intact?

Let's say I wanted to replace something like this:

\section{Introduction}

with this:

<h1>Introduction</h1>

in notepad++.

Essentially, find and replace all the opening tags (in this case the "\section{" part) and closing tags (the "}") with different opening and closing tags,Something like this

Something like this. Except, of course, the text in between the tags stays the same. Is this possible within notepad++?

Upvotes: 0

Views: 504

Answers (2)

deathpote
deathpote

Reputation: 250

Search :

\\section\{(.*)\}

And replace with :

<h1>\1</h1>

\1 will be replaced with your first regexp result.

I.e. searching :

\{(.*), (.*)\}

And replacing with :

[\1, \2]

Will transform {foo, bar} into [foo, bar] :

\1 = foo \2 = bar

Upvotes: 0

vempo
vempo

Reputation: 3153

Find what: \\section\{(.+)\}

Replace with: <h1>\1</h1>

Here, the parentheses (.+) define a group that consists of one or more character, and \1 references the contents of the group.

Upvotes: 1

Related Questions