我正在尝试使用preg_match_all从文本数组格式中提取数组:
解释:我有这种文字
mynicetext
text with other elements
|my first Column |my second column |
|my data in first column |data 2 |
|my data in first column |data 3 |
....
other text
text with other elements
|my first Column |my second column | My last column |
|my data in first column |data 2 |data 2 |
|my data in first column |data 3 |data 2 |
....
我想像这样提取一个完整的数组:
|my first Column |my second column |
|my data in first column |data 2 |
|my data in first column |data 3 |
我试图用这个~(\s*\n)\|(.*)\|(\s*\n)~
来提取,但我剪切了由回车引起的线条。
|my first Column |my second column |
然后
|my data in first column |data 2 |
...
有什么想法吗?
答案 0 :(得分:1)
您可以使用preg_match_all尝试此操作:
$pattern = '~(?:^\|.*\n)+~m';