Skip to content
Advertisement

Php Regex: how to match repeated patterns

given following text

JavaScript

I need to capture columns values. I thought something about these lines:

JavaScript

But unfortunately it captures only first column.

JavaScript

Any suggestion? Thanks `

====EDIT==== Just to be clear: i know that i could preg_match searching for d+ values or split the whole string in lines and run explode on the each line, but I’m interested in regex solution where I have first column as first member of resulting array(actualy forgot to put capturing braces in the first draft of question), and following columns with data, every line putted in it’s dedicated array…

Advertisement

Answer

Why use preg_match or preg_match_all at all?

JavaScript

This should work as long as there is no more than one : on every line. Seems to me like it’s the shortest and fastest way to write this too.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement