Sun
Sun

Reputation: 3564

How to replace/delete lines starts with particular word in Eclipse?

Some cases, I have to replace/delete lines starts with particular word like 'public' 'private' Java classes or <version> for XML file.

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${version.bean.validation.hibernate}</version>
        </dependency>

Here using find/replace, I want to delete all lines starts with '<version>'. How to achieve this.

Upvotes: 14

Views: 10415

Answers (3)

J-Dizzle
J-Dizzle

Reputation: 5143

Use the following regular expression to hide lines starting with 'public' -

Regex Line Replacement

  • public(.*)\R

Eclipse Config

enter image description here

Example

enter image description here

Upvotes: 5

Sumit Singh
Sumit Singh

Reputation: 15886

See the image:

  1. add regular expression as Jens correctly mentioned ^\s+<version>.*$
  2. put nothing in here.
  3. Check on regular expression option.
  4. Click Replace All.

enter image description here

Upvotes: 9

Jens
Jens

Reputation: 69440

use this regexp: ^\s+<version>.*$ This will remove all lines starting with <version>. Make sure you have checked the checkbox "Regular expression"

Upvotes: 15

Related Questions