0

I'm basically working on custom query building. I've designed the pattern as field_set and sub_field_sets. A sample Query:

({e:3}.{f:44}.{f:2}) + ( 
                   ({e:3}.{f:44}.{f:3}) + ({e:3}.{f:44}.{f:4}) 
                        ) - ({e:3}.{f:44}.{f:5})

I want to get all operators from root using REGEX. Which in this case should result ['+', '-'] and NOT ['+', '+', '-']

Sarmad
  • 315
  • 1
  • 4
  • 15
  • It's quite unclear what you're asking. You need to provide more examples, give us the list of possible operators, etc. From what you posted, using `strpos($query, $operator) !== false` for each operator should work, at least... – Jeto Nov 22 '18 at 07:44

1 Answers1

0

This works on given sample:

([+-])(?![^+)-]+\)\s*\))
Khazul
  • 179
  • 6
  • You can shorten your regex a bit with removing the escapes for `+` and `-` in character classes. They are not required if these are only characters in the character class. – Asunez Nov 22 '18 at 08:33
  • You missed slash in `[^+\-)]` for even one more byte saved :P Just move `-` as last character in character class :P – Asunez Nov 22 '18 at 09:09