Hello,
I'm a beginner with regex. I have a peace of code and there they use regex with preg_replace and preg_replace_callback.
- This is my string: 21 sep 15:30: team 1 - team 2
- At the moment (I have tried a lot) this is my regex: #((\d*) (.{3}))( (\d{2}):(\d{2}):)(.*)(\s\-\s)(.*)#
- And this is the result with preg_match:
array[0] - 21 sep 15:30: WSV DS 1 - Favorita DS 1
array[1] - 21 sep
array[2] - 21
array[3] - sep
array[4] - 15:30:
array[5] - 15
array[6] - 30
array[7] - team 1
array[8] - -
array[9] - team 2
What I want is this:
array[0] - 21 sep
array[1] - 15:30:
array[2] - team 1
array[3] - -
array[4] - team 2
Can somebody help me to get this in the right direction?
Thanks.
Nioc
I hope that someone can give me the solution
Moderator: General Moderators
Re: I hope that someone can give me the solution
It's not possible to get that exact array but you can get
How? By removing the extra parentheses in your expression that aren't doing anything.
And with a small tweak for some unwanted spaces,
Code: Select all
array[0] - 21 sep 15:30: WSV DS 1 - Favorita DS 1
array[1] - 21 sep
array[2] - 15:30:
array[3] - WSV DS 1
array[4] - -
array[5] - Favorita DS 1Code: Select all
#((\d*) (.{3}))( (\d{2}):(\d{2}):)(.*)(\s\-\s)(.*)#
^ ^ ^ ^Code: Select all
#(\d* .{3}) (\d{2}:\d{2}:) (.*)(\s\-\s)(.*)#