We help IT Professionals succeed at work.
Get Started

regular expression

702 Views
Last Modified: 2008-01-09
Hi, I'm using KFileReplace under linux, to replace a block of text in several files.

That's an example of file:

***BEGIN FILE***

<body>
<a name="top"></a>
<div id="content">

<H2><A NAME="titleofpageanchor"></A>Title of page</H2>

<P>Some text</P>
<P>Some more text.</P>
<hr>
<H2><A NAME="anotheranchor"></A>Another title</H2>
<P>Bla bla bla. </P>
<P>Another bla bla.</P>
<H2><A NAME="anchor3"></A>3rd Title</H2>
<P>3rd chapter text.</P>

***END FILE***

I've tried with the following expression:

<div id="content">.+</H2>

The problem is that this expression will match from "<div id="content">" till "3rd Title</H2>" (last occurrence of </H2> in the file).

I want to select only from "<div id="content">" till "Title of page</H2>" (first occurrence of </H2> in the file).

Please let me know which regular expression to use to achieve this.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE