Reputation: 371
Hi I am trying to use a regex to replace a "/" with "/n:". The problem I am having is that I want this to happen unless the "/" is followed by an "@" so "/@".
I had a pattern like this "//[^@]/" and while this gets the "/" while ignoring any "/@" it also matches the following letter. I just need to match the "/". Can anyone help with this thanks.
Edit: Added example string
/module/y-version/@value
Upvotes: 2
Views: 569
Reputation: 626738
You can use a negative lookahead:
'~/(?!@)~'
See the regex demo
The [^@]
is a negated character class, and is a consuming pattern, while the lookahead will only check the text to the right of the current location in the string, and will fail the match if the lookahead pattern finds the match.
Upvotes: 3