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

In some cases, I have to replace / delete lines starting with a specific word like "public" 'private' of the Java classes or <version> for the 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 all lines to start with '<version>' . How to achieve this.

+7
eclipse regex
source share
3 answers

use this regex: ^\s+<version>.*$ This will delete all lines starting with <version> . Make sure you select the Regular Expression check box.

+6
source share

See image:

  • add regex, as Jens ^\s+<version>.*$ correctly pointed out
  • do not put anything here.
  • Check regex parameter.
  • Click Replace All .

enter image description here

+5
source share

Use the following regex to hide lines starting with "public" -

Regex Line Replacement

  • public(.*)\R

Eclipse Configuration

enter image description here

Example

enter image description here

0
source share

All Articles