JCarter
JCarter

Reputation: 267

Match everything before first colon including colon and following spaces

I'd like to match a string so that

A: B: C

would return the match (note the space behind the colon)

A: 

It matches everything until the first occurrence of a colon, but includes the colon and any spaces behind of it.

The pattern ^[^\:]+ would return A but not the colon and the spaces.

Upvotes: 2

Views: 5904

Answers (1)

timgeb
timgeb

Reputation: 78780

Almost. Use

^[^:]*:\s*

Demo and explanation: regex101.com

Upvotes: 7

Related Questions