0

I'm trying to figure out a regex (in PHP) to find

<ANYTHING_BUT_WHITSPACE>? OR ?<ANYTHING_BUT_WHITSPACE>

and replace the ? with a blank space. So, '?test test?' should become 'test test'. I have one working in java

"(?<=\\S)\\" + "?" + "|\\" + "?" + "(?=\\S)"

Any idea what it would be in PHP?

1 Answer 1

1

There is probably a better pattern but almost the same:

echo preg_replace('/(?<=\S)\?|\?(?=\S)/', '$1', '?test test?');
  • Need delimiters in this case I used /
  • Don't concatenate with + use . but not needed
  • No need to double escape \\
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.