Doug Smith
Doug Smith

Reputation: 29316

How do I find all occurrences of a character that *aren't* the first character in the line?

I want to find all occurrences of the ">" character that are not at the beginning of the line.

For example:

This is a <em>test</em>, this is not a drill.

> Shouldn't

The first two ">" should be caught, but the last shouldn't, as it starts a line.

I tried: (?<!$)> to no avail.

Upvotes: 1

Views: 48

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

Use a negative look-behind :

/(?<!^)>/gm

Demo https://regex101.com/r/wW2hO3/1

Note that you need use multi-line flag (m) which makes the regex engine match the anchors for each line, instead of whole of string.

Upvotes: 3

Related Questions