Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
^(text[ ]*=[ ]*)'((?(?!item_1[,]?).)*)'
/
gm

Description

  • matches only lines that do not contain the string
  • uses negative look arounds
  • appends the new item always to the back
  • suffers from a leading comma in case the list was empty
Submitted by @ubunatic - 9 years ago