user2132188
user2132188

Reputation: 177

Notepad++ Regex based on position of character

For Example lets say I have those Lines

Example123 23 456 45 - car - bus
Example34 2123 - school
Example67 today - truck - Train

I want to delete ONLY expressions which located before "first" (-). How I can match the character position with Regex?

Upvotes: 1

Views: 1100

Answers (1)

Daniel Gimenez
Daniel Gimenez

Reputation: 20504

The following will match everything before the first - on a line:

^.*?(?=-)

REY

This works by matching the start of the line, then matching any character 0 or more times, until it sees a "-" character, but doesn't include that in the match since it's a look ahead (?=-).

  • Example123 23 456 45 - car - bus => - car - bus
  • Example34 2123 - school => - school
  • Example67 today - truck - Train => - truck - Train

If you don't want to include the dash and white space change it to:

^.*?-\s*

Also you might have to check matches newline as an option to work in Notepad++ so ^ matches start of a line.

Upvotes: 2

Related Questions