[英]Regex preg_match between this {# … #}
I do like to create a preg_match between this 2 string start here "{#" and ends here "#}";我确实喜欢在这 2 个字符串之间创建一个 preg_match,从这里开始“{#”到这里结束“#}”;
what is the best way to extract the data between this ?在这之间提取数据的最佳方法是什么?
"/{#(.*?)#}/"
I have leaner that there is an APP https://www.phpliveregex.com/我有一个 APP https://www.phpliveregex.com/
"/\{\#(.*?)\#\}/g"
Also learn regex here http://regex101.com/还可以在这里学习正则表达式http://regex101.com/
Edit:编辑:
Would you share some of your code because it works fine.你会分享你的一些代码,因为它工作正常。 Here is a test of the regex这是正则表达式的测试
http://regex101.com/r/aC1fT2/1 http://regex101.com/r/aC1fT2/1
and here it is in action:这是在行动:
~
⚡⚡⚡ more test.php; php test.php
<?php
//The source code
$pattern = "/\{\#(.*?)\#\}/";
$test_string =
"
Lorem Ipsum is simply {#dummy#} text
of the printing and typesetting industry.
Lorem Ipsum has been the industry's {#standard#} dummy text
ever since the 1500s,
when an unknown printer took a galley of type
and scrambled it to make a type specimen book.
It has survived not only five centuries,
but also the leap into electronic typesetting,
remaining {#essentially unchanged#}.
It was popularised in the 1960s
with the release of Letraset sheets
containing Lorem Ipsum passages,
{#and more recently with desktop publishing software#}
like Aldus PageMaker including versions of Lorem Ipsum.
";
preg_match_all($pattern, $test_string, $matches);
print_r($matches);
?>
...
//The output
Array
(
[0] => Array
(
[0] => {#dummy#}
[1] => {#standard#}
[2] => {#essentially unchanged#}
[3] => {#and more recently with desktop publishing software#}
)
[1] => Array
(
[0] => dummy
[1] => standard
[2] => essentially unchanged
[3] => and more recently with desktop publishing software
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.