Regular Expressions 101

Community Patterns

RegEx to remove hyphens between two search and found strings

0

Regular Expression
PCRE (PHP <7.3)

/
(?<=\G(?!^)|clients_field_)(\w*)-
/
g

Description

Try a regex based on \G anchor for chaining matches to the desired starting point.

(?<=\G(?!^)|clients_field_)(\w*)- Replace with what was captured inside the first capturing group.

$1 (?<= opens the lookbehind \G(?!^) continues matching on last match but not at ^ start or |clients_field_ match position where the substring is behind (\w*)- capture zero or more word characters followed by - See this demo at regex101

Submitted by anonymous - 4 years ago