I want to separate at the “|” and check the length to at least 3 characters
$input_line = "test test | teste test test3 | test test 4" preg_split('/(.|.)/', $input_line); // Have tried: preg_split('/(.|.)^[a-z0-9*]{3}$/', $input_line);
Can anybody help me? https://www.phpliveregex.com/p/AdQ
Advertisement
Answer
I think doing this in a regex might not be the best tool for the job, but if you want to use it here might be a possibility:
(?:^||) # start at the start of a line or with a `|` ([^|]{3,}) # before the next '|', make sure it has length >= 3 (?:||$|n) # up until the next '|' or 'n' or '$'
https://regex101.com/r/Pz3YCH/1
Again though, I think doing a string split would be much better though.