$str="This is a string with <xref cite@#>test</xref> and
<xref cite@#>string2</xref>";
「@#> test」と「xref」の間の文字列を取得する必要があります。
私は試した:
$start=strpos($str,"@#>test");
$end=strpos($str,"xref ",$start); //here how to search backwards from "@#>test"
//to "xref "
期待される出力:引用
strrpos-文字列の最後の出現を取得するためだけです。指定された位置から文字列を逆方向に検索する関数はありますか?
これを試してください:正規表現による(?<=xref).*(?=@#)
$re = "/(?<=xref).*(?=@#)/m";
$str = "This is a string with <xref cite@#>test</xref> and \n<xref cite@#>test</xref>";
preg_match_all($re, $str, $matches);
[ライブデモ] [1]
更新: (?<=<xref).*?(?=@#)
$re = "/(?<=<xref).*?(?=@#)/m";
$str = "This is a string with <xref cite@#>test2</xref> and <xref cite@#>test1</xref><xref cite@#>test</xref><xref cite@#>test1</xref>\n<xref cite<e.g.>[p.11]@#>test</xref>";
preg_match_all($re, $str, $matches);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加