Nakahed
Nakahed

Reputation: 61

How to capture part of name without optional group

I'm adding information about part and version of the process (some of them are without this information) and i want to capture name of process- how can i do it?

I was trying to use pattern: (.+)(?:p\d+ v\d+)?$, but it doesn't work

Sample of names:

Process name 1

Other proces 2 p1 v35

Process 1 does sth p32 v5

Inputs:

Other process 2 p1 v35 Process 1

Results (expected)

Other process 2

process name 1

Upvotes: 0

Views: 48

Answers (1)

Robo Mop
Robo Mop

Reputation: 3553

You could try:

^(.+?)(?=p\d+\s*v\d+\s*$|$)

As seen here

Explanation:

I used a positive lookahead, which you can learn more about by clicking on this link.

Basically, I match everything from the start of the line, until the point where you get a p1 v35, or until the end of the line.

Upvotes: 1

Related Questions