1

I had a paragraph:

aaa-bbb-cc/my-text">my-text sas
//domain.com/my-text'> this is my-text

I want to replace all string 'my-text' to 'my replace tex' if they are not just after character '/' like:

aaa-bbb-cc/my-text">my replace text sas
//domain.com/my-text'> this is my replace text

Thank you

1 Answer 1

2
(?<!\/)my-text

(?<!\/)Negative Lookbehind

since it's javascript, which does not support negative lookbehind, you can do this way:

(?=([^\/]|^)(my-text))

group 2 is your expect.

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

3 Comments

It doesn't work with me str = str.replace((/?=([^\/]|^)(my-text))/gi, "my replace text"); and this work: str = str.replace(/([\/])?my-text/gi, function($0,$1){ return $1?$0:'my replace text';})
thanks @mynotmypt, (?=([^\/]|^)(my-text)) only can be used for match, can't do replace with it.

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.