0

I try to find all occurences of <? on my site to replace them with <?php but occurences of <?php should be ignored.

Otherwise it would change <?php as well and would replace <?php with <?phpphp

Attempt: <\?\b(?!php)\b

Regex101

1 Answer 1

2

You don't need the word boundaries. You can use the RegEx <\?(?!php)

  • <\? matches <?

  • (?!php) makes sure your match isn't followed by php

Demo.

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

1 Comment

Note to myself: You can add more ignore string if you separate them with the pipe | e.g. <\?(?!php|=). This ignores <?php and <?=.

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.