Keith Marchen
Keith Marchen

Reputation: 11

How to capture only last match in Regex

I have the string below (including line breaks) that is returned from a TFS 'Labels' command. I need to match against only the last build number (build.2).

How do I build a regex expression to do this?

Label                                                  Owner          Date      
---------------------------------------------------- -------------- ---------- 
ICSExternalGateway-04_MJR-ICSExternalGateway-build.0 Marchen, Keith 2/25/2015 
ICSExternalGateway-04_MJR-ICSExternalGateway-build.1 Marchen, Keith 2/25/2015
ICSExternalGateway-04_MJR-ICSExternalGateway-build.2 Marchen, Keith 2/25/2015 

Upvotes: 1

Views: 1109

Answers (2)

David Faber
David Faber

Reputation: 12495

You might try something like this. It works because ordinarily the wildcard character . does not match a newline:

(build.\d).*$

See Regex 101 Demo here for example and full explanation.

Upvotes: 0

vks
vks

Reputation: 67988

build\.\d+(?![\s\S]*\bbuild\.\d+)

Try this.See demo.The lookahead will make sure there is no build ahead.

https://regex101.com/r/wU7sQ0/14

Upvotes: 1

Related Questions