-2

Basically I have a bunch of strings in a database and I need to split them into 3 parts. First part should be the very first word, nothing else, so I can use explode for that. The second and third parts are tricky, as the string and word length is not consistent, for example:

  • Michelin Alpin 3 185/70 R14 GRNX --> [Michelin] [Alpin 3] [185/70 R14 GRNX]
  • Continental VancoWinter 2 225/75 R16C C M+S --> [Continental] [VancoWinter 2] [225/75 R16C C M+S]
  • Kleber VIAXER 175/70 R13 82T --> [Kleber] [VIAXER] [175/70 R13 82T]

I tried quite a few regex patterns to get these 3 parts back, but no luck so far. I would really appreciate any ideas!

1 Answers1

0

Unfortunately I cannot see a clear and concise logic to follow. The second part is Alpin 3 and VancoWinter 2, but not VIAXER 175. So you first need to define your desired outcome.

However, just based on these examples, this might or might not work:

^(\S*) (.*) (\d+\/\d+.*)

Try it online: https://regex101.com/r/4rtbxS/3

It consists of 3 parts:

  • Anything until the first space
  • anything until the next match, which is
  • digits, followed by a slash, followed by more digits, followed by whatever remains
Zsolt Szilagyi
  • 3,909
  • 4
  • 23
  • 40
  • Sorry if I wasn't clear. The string should be split up like this: 1st part = 1st word 2nd part = up until the 3 digits followed by "/" 3rd part = everyting from the 3 digits followed by "/" The regex you wrote works like a charm actually, so thank you! – Balázs Kozma Oct 17 '20 at 14:42
  • Sure. What I mean is: Examples are not a definition.They are based upon human intuition on why "WancoWinter 2" is a brand but "Viaxer 175" is not. – Zsolt Szilagyi Oct 17 '20 at 14:45