0

say I have

job.batch/monitoring-cloud12390200

or

service/monitoring-opentt-collector

I want to match job in the first and service in the second.

I know I can use positive lookahead to match the string up to and if it has a / by using .*((?=\/))

But this will give me job.batch in the first

What I want to do is match the string up to the first / or ., whichever comes first.

ryan
  • 81
  • 6

1 Answers1

2

Use this regex:

^[^\/.]+

See proof

NODE EXPLANATION
^ the beginning of the string
[^\/.]+ any character except: '/', '.' (1 or more times (matching the most amount possible))
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37
  • 1
    oh thank you so much! I guess when writing regular expressions it's easy to get so focused on doing it a certain way, that it's helpful to completely start over and think of other ways to go about it. – ryan Feb 04 '21 at 15:55