-1

I want to extract a string whether it is at the beginning of a sentence or the end it has to be the whole word. The expression should work in both PCRE and POSIX.

Example:

input strings=['ALLY [&] MORTY','[&] ME', '[&]']
---> match is in bracket
1
  • Are the brackets actually in the string? Commented Sep 26, 2023 at 19:51

1 Answer 1

0
(^| )(&)( |$)
  • (^| ) matches either the beginning of the string or a space
  • (&) matches the literal string &.
  • ( |$) matches either a space or the end of the string.

The match will be in capture group 1.

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.