3
Good evening, everyone,
Thank you for visiting and proposing to help me. I’m terrible at regex so I’ve come to ask for your help.
I have the following string that can also vary as example:
string(49) "02/12/2018 (Assessment 2) = /86= | Weight: 50.00%"
string(49) "02/12/2018 (Assessment 2) = 50.83/86= | Weight: 50.00%"
In the first case even without the amount I need to collect 00.00.
I need to extract in an array as follows:
$dados[ "date" ] = "02/12/2018"
$dados[ "markOK" ] = "50"
$dados[ "markTotal" ] = "86"
$dados[ "weight" ] = "50.00"
Other examples of output:
string(49) "02/12/2018 (Assessment 2) = /86= | Weight: 50.00%"
string(59) "06/11/2018 (Assessment 2) = 22.40/35=32.00 | Weight: 50.00%"
string(49) "04/12/2018 (Assessment 2) = /60= | Weight: 50.00%"
string(59) "11/09/2018 (Assessment 2) = 27.00/40=33.75 | Weight: 50.00%"
string(59) "09/09/2018 (Assessment 2) = 30.00/30=50.00 | Weight: 50.00%"
string(59) "14/08/2018 (Assessment 2) = 31.00/40=38.75 | Weight: 50.00%"
string(59) "19/06/2018 (Assessment 2) = 63.00/72=43.75 | Weight: 50.00%"
string(59) "17/06/2018 (Assessment 2) = 45.00/45=50.00 | Weight: 50.00%"
string(59) "22/05/2018 (Assessment 2) = 11.00/55=10.00 | Weight: 50.00%"
Edit the question with the code of what you’ve already tried to analyze.
– Sam
@Sam I could not develop any reasoning in regex for the solution, only using substring, but as the data may vary from position the code broke =/
– Gustavo Filgueiras
@Gustavofilgueiras Even so, it is important to put the code you have tried to do and what errors are occurring. And if the string can change, it would be interesting to also put all the possibilities (or if there are many, some examples followed by an explanation of how it can vary). Please click on [Edit] and add these details. And I suggest you read the [tour] and the pages [Ask] and [mcve] to better understand how questions should be.
– hkotsubo
@Sam thanks plea tip, I edited with the other example that may vary, but on the issue of code, I really did not get any advance, sorry.
– Gustavo Filgueiras
@Sam Eu think which is in the first case, in
/80
(since there is no "50" before the bar, then the value must be zero). At least that’s what I understood...– hkotsubo
@hkotsubo Exactly that my comrade !
– Gustavo Filgueiras
@Sam, it can be 00 or 00.00 is pq sometimes the value is also broken in real, like: 50.43
– Gustavo Filgueiras
@Sam edited it too, sorry
– Gustavo Filgueiras
Sorry I can’t be of more help, but I’ll have to hang up now. Anyway, if the only variation is that the "50" before the bar is optional, I think using a combination of
strpos
,strrpos
andsubstr
maybe it’s easier than regex. But if you really want to use regex, you can take a look at some tutorials, like that and that– hkotsubo
@hkotsubo Thank you man
– Gustavo Filgueiras
In the case of
86=
you just want to86
(without the=
)... and in the case of40=33.75
?– Sam