Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

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.

like image 307
Sun Avatar asked Dec 17 '14 09:12

Sun


3 Answers

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

like image 53
J-Dizzle Avatar answered Oct 26 '22 10:10

J-Dizzle


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

like image 27
Jens Avatar answered Oct 26 '22 10:10

Jens


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

like image 36
Sumit Singh Avatar answered Oct 26 '22 09:10

Sumit Singh