wiki
wiki

Reputation: 2063

regular expression: how to capture this group?

a sample of my text is:

per se: of itself. 
ovo: from the beginning. 
abattoir: a slaught: erhouse. 

the capture group structure is:

enter image description here

group 1: from the beginning of the line till first :

group 2: : (colon+1space) right after end of group 1

group 3: right after end of group 2 till end of the line

my pattern is:

(^\w+)(: )(.+$)

everything with this pattern is ok except this fact that it fails to match first line of the sample text(per se: of itself. )

any idea for modification of the pattern (or maybe a new pattern) so that it matches all of the lines?

Upvotes: 2

Views: 73

Answers (1)

Flup
Flup

Reputation: 625

How about

^([^:]+)(: )(.+$)

i.e. match everything that isn't a colon (per your spec).

Upvotes: 4

Related Questions