1

I'm trying to get a string which matches by a regex pattern ( {$ ... } ). But I don't want the brackets and the $ sign returned.

For example

{$Testpath}/Testlink

should return

Testpath

My regex pattern looks like this at the moment:

^{\$.*}$
2
  • Why you're using ^ and $ - is the value should be captured only if the entire containing string matches the rule? Commented Sep 10, 2013 at 8:27
  • 1
    a ^{\$(.*)} will give you a match in the match array. You don't need the last $ in your regex because it matches the end of the string but your searched value isn't at the end. Commented Sep 10, 2013 at 8:28

1 Answer 1

3

Try the following regex:

^\{\$\K[^}]*(?=\})

Regex101 Demo

This expression mathces start-of-string ^ then a literal { then a literal $ then it ignores those using \K anchor, then it matches one or more characters which aren't a } then it looks ahead (?=\}) for a literal }.

You may not need the end-of-line anchor $ because the text you are trying to match might not end at the end of the string and you may not need the start-of-line ^ anchor for the opposite reason, that is the pattern you are trying to match may not be at the start of the string or line.

I think you should remove ^ and $ and use the global modifier.

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

Comments

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.