1

I can't capture what i want with capturing parantheses... I'm searching in /hodsakers/marsh-zwartArray/d and i want to capture marsh-zwartArray but sometimes the last / is not present in what i'm searching. I search and try many things =/ like :

(marshall[\s\S]*)\/

it work but if the last backslash is not present it doesn't. I also try

(marsh[\s\S]*)(\/)?

in this case that's the opposite, it work without the last backslash but not anymore if there is one, it will get all the string and capture nothing =/ So i don't know how i can capture in both cases =/ Thanks for your help

2
  • 2
    Perhaps, just /marsh[^\/]*/ is enough. Commented Jul 19, 2016 at 22:21
  • Do you want to match with all occurrences of 'marsh*' ? For example for the following case is going to match for twice if you example above /hodsakers/marsh-zwartArray/whatevermarsh Commented Jun 26, 2017 at 14:08

1 Answer 1

2

You may use a [^\/]* negated character class to match 0+ chars other than /:

/marsh[^\/]*/

See the regex demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, it was the negated character, problem is solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.