NotAgain
NotAgain

Reputation: 1977

Need to refine this regex expression

The input I can get might be

/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22

or

/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22/Demo.Tests/AverageTests.cs

I need to extract in both cases.

/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22

Regex:

^(.*?)tags

is matching till

/DemoSystems/DemoFramework/MyRepo/MyModule/tags

And added complexity is that 2015_02_22 can be anything. A mix of number alphabets and whitespaces. Basically depends on developer. So in other words I have to match till 'tags' + the next folder after it.

Any pointers?

Upvotes: 1

Views: 35

Answers (1)

hek2mgl
hek2mgl

Reputation: 158210

You can use:

.*?tags\/[^\/]+

It will match anything from the start of the line until the word tags, the / after the word tags and the following characters until another / (excluding that) or the end of the string.

Online demo

Upvotes: 2

Related Questions