A K
A K

Reputation: 153

How to find all lines of code that start and end with specified string in VScode (using Regular Expression)

How to find all lines of code that start and end with specified string in VScode and replace some part of those line with other string (using Regular Expression)?

For Example:

1. Find all lines that start with import and end with .ts (with any number or chars allowed in between)

2. Delete only .ts part from all those lines

For example:

It should match lines like

import { AddToCompare } from '@Booking/core/modules/compare/AddToCompare.ts'

and then remove .ts from end from all those lines to make it

import { AddToCompare } from '@Booking/core/modules/compare/AddToCompare'

PS: To find lines starting with import I used ^\s*import but dont know what expression to use for rest of the pattern.

Also most solutions here are for python and grep but not for vscode.

Upvotes: 1

Views: 3171

Answers (1)

rioV8
rioV8

Reputation: 28703

Find

^(\s*import .*)\.ts'$

Replace

$1'

Upvotes: 2

Related Questions