I’ve got a problem. I need to find different text tables in text like:
+--------------------+--------------------+---------------------+
| Some data | Some results | Some things |
| | | (modules) |
+--------------------+--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
| +--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
| +--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
+--------------------+--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
| +--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
| +--------------------+---------------------+
| | | |
| | +---------------------+
| | | |
+--------------------+--------------------+---------------------+
or like
+--------------+--------------+-------------+----------+-----------+
| Name |Age | Possible | Good | Bad |
| | | | | |
+--------------+--------------+-------------+----------+-----------+
| 1 | 2 | 3 | 4 | 5 |
+--------------+--------------+-------------+----------+-----------+
| Allgood things | |
+--------------+--------------+-------------+----------+-----------+
| | | | | |
+--------------+--------------+-------------+----------+-----------+
I am trying to find every thing starting with +– which ends with -+ and after come white spaces or words or numbers like this:
$pattern = '/\+(-)+(.*)(-+\+[\s\d\w]+)/mis';
preg_match_all($pattern, $this->document, $matches);
I found content starting from one table beginning till last table end. But I want to find all tables in document.
Please help.
Try this
See it here on Regexr
This will find a table that starts with a row consisting of
+and-. The^matches the start of the row and the$matches the end of the row. The there is a whitespace, this is needed to match the newline characters.Then comes a group that defines a row in a table: It has to start with a
+or a|, then there can be any character till the end of the row. This complete group will be be repeated till there is a row not starting with one of those characters.