2

I need to split 1/2 chicken/‏ greens/egg/tomato/blue cheese/bacon for / only if the / is surrounded by [a-z ] and not by numbers

I have tried:

  • #[^0-9]\/[^0-9]#i
  • #[a-z ]\/[a-z ]#i
  • #(?:[a-z ])\/(?:[a-z ])#i

But it capture also the text

(If it matters, I am using preg_split in PHP where the modifier g is always implicitly used)

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
Fabrizio
  • 3,734
  • 2
  • 29
  • 32

1 Answers1

2
(?<!\d)\/(?!\d)

You can split by this.Use lookarounds.See demo.

https://regex101.com/r/sJ9gM7/101

EDIT:

(?<=\D)\/|\/(?=\D)

Use this it / having an integer on one side should be split.

vks
  • 67,027
  • 10
  • 91
  • 124