我正在尝试获取一个不被任何其他数字包围且不在数字序列中的六位数字。该数字可以存在于字符串的开头、字符串中的任何位置以及末尾。它前面还可以有逗号和文本,但最重要的是不同的 6 位数字块。我已经竭尽全力进行前瞻和条件处理,但找不到解决所有问题的完整解决方案。
样本数据:
00019123211231731订单号 761616 BR 地址 123 A ST 订单号。760641 约翰·多伊 参考号:订单#761625 OP212312165 订单号 759699 /REC/YR 123 A ST 766911 761223,761224,761225
我想知道这里的反向引用有什么问题:
preg_match_all('/__\((\'|")([^\1]+)\1/', "__('match this') . 'not this'", $matches);
Run Code Online (Sandbox Code Playgroud)
它应该匹配__('')之间的字符串,但实际上它返回:
match this') . 'not this
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要拆分以下字符串并将每个新行放入一个新的数组元素中.
this is line a.(EOL chars = '\r\n' or '\n')
(EOL chars)
this is line b.(EOL chars)
this is line c.(EOL chars)
this is the last line d.(OPTIONAL EOL chars)
Run Code Online (Sandbox Code Playgroud)
(请注意,最后一行可能没有任何EOL字符.字符串有时也只包含1行,根据定义,它是最后一行.)
必须遵循以下规则:
所以这应该导致以下数组:
[0] => "this is line a."
[1] => "this is line b."
[2] => "this is line c."
[3] => "this is the last line d."
Run Code Online (Sandbox Code Playgroud)
我尝试过以下操作:
$matches = array();
preg_match_all('/^(.*)$/m', $str, $matches);
return $matches[1];
Run Code Online (Sandbox Code Playgroud)
$ matches [1]确实包含每个新行,但是:
无论如何,我一直在玩'\ R'和诸如此类的东西,但我找不到符合我上面概述的两条规则的好的正则表达式.有什么帮助吗?
我是正则表达式的新手.我想从网页源中获取一些数据.我曾经
file_get_contents("url")获得该页面的HTML源代码.现在我想在一些特殊标签中捕获一部分.
我preg_match_all()为此找到了作品.现在我想要一些帮助来解决我的问题,如果可能的话,帮助我找出如何解决这样的类似问题.
在下面的示例中,我如何获取数据<ul>?(我希望这个示例HTML代码可以让我更容易理解.)
<div class="a_a">qqqqq<span>www</span> </div>
<ul>
<li>
<div class="a_a"><h3>aaaa</h3> aaaa aaaaa</div>
</li>
<li>
<div class="b_b">bbbbb <span class="s-s">bbbb</span> bbbb</div>
</li>
<li>
<div class="c_c d-d">cccc cccc ccccc</div>
</li>
</ul>
<table>
<tr>
<td>sdsdf</td>
<td>hjhjhj</td>
</tr>
<tr>
<td>yuyuy</td>
<td>ertre</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud) 我想从字符串中提取年份。我得到了一个不完整的解决方案。我的字符串总是这样:
请留言 2014 年和 2015 年以上爵士乐的 mpg 至我的手机号码 +123456789
我尝试过以下正则表达式;
preg_match_all('!\d{4}+| \d{4}+\W!', $str, $matches);
Run Code Online (Sandbox Code Playgroud)
这将输出以下数组。
Array
(
[0] => Array
(
[0] => 2015
[1] => 2014+
[2] => 1234
[3] => 5678
)
)
Run Code Online (Sandbox Code Playgroud)
我只需要获取带有 + 符号的年份部分(如果有)。即,我只想要这个:
Array
(
[0] => Array
(
[0] => 2015
[1] => 2014+
)
)
Run Code Online (Sandbox Code Playgroud) 鉴于输入字符串“ othertext ?.abc.de.fgh.i moretext ”和模式'/\?(\.[a-zA-Z]*)*/'我正在尝试使用函数preg_match_all来获取数组与元素.abc、.de、.fgh和.i匹配,但只有?.abc.de.fgh.i和.i匹配。(测试)
有没有办法告诉preg_match_all使用跳过前两个匹配的第三个匹配?例如,我有以下HTML
<div class="entry">
<div class="text">BlaBlaBla</div>
<div class="date">2009-10-31</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要preg_match_all来获取最外层div的内容,而不是在它遇到的第一个/ div处停止.
我正在尝试从网页获取所有图像标签的src。但是我对于如何不匹配括号内的模式感到困惑。在这种情况下gif|jpg|png|jpeg
$img_src_pattern = '/src="?.+\.(gif|jpg|png|jpeg)"/';
preg_match_all($img_src_pattern, $contents, $img_matches);
Run Code Online (Sandbox Code Playgroud)
所以当打印出来时,$img_matches我得到一个像这样的数组:
Array (
[0] => Array (
[0] => src="http://s9.addthis.com/button1-bm.gif"
[1] => src="http://s9.addthis.com/button1-bm.gif" )
[1] => Array ( [0] => gif [1] => gif )
)
Run Code Online (Sandbox Code Playgroud)
这就是我想要得到的:
Array (
[0] => Array (
[0] => src="http://s9.addthis.com/button1-bm.gif"
[1] => src="http://s9.addthis.com/button1-bm.gif" )
)
Run Code Online (Sandbox Code Playgroud)
这真的preg_match使我感到困惑。你能启发我吗?
我一直在寻找类似的问题,但没有发现任何人有类似的问题或可能的解决方案.我有preg_match_all函数,它找到了5个匹配项并将它们返回到数组中.如何计算数组中的字符串?
preg_match_all("/\)\">(.*?)<\/a>/s",$value,$counter);
here is var_dump(counter[1]):
array (size=1)
0 => string 'word1' (length=..)
array (size=1)
0 => string 'word2' (length=..)
array (size=1)
0 => string 'word3' (length=..)
array (size=1)
0 => string 'word4' (length=..)
array (size=1)
0 => string 'word5' (length=..)
Run Code Online (Sandbox Code Playgroud)
正如你所看到的那样,它返回了我的5场比赛,但是我不能打印那个数字array_count_values,count()...我已经尝试了爆炸,然后得到字符串,但也count()不会工作.
count($counter[1]) returns me ->
int 1
int 1
int 1
int 1
int 1
Run Code Online (Sandbox Code Playgroud)
我需要获得一些比赛,我没有更多的想法,所以任何事情都是非常受欢迎的.
更新:这是var_dump($ value);
string '<h2><a href="javascript:Organigram.toggle('organigram_section_29')">word1</a></h2><div class="show"><p class="nums"><span class="phone">03 839 11 00</span></p>' (length=170)
string '<h2><a href="javascript:Organigram.toggle('organigram_section_35')">word2</a></h2><div class="show"><p class="nums"><span class="phone">03 …
我正在尝试从以下URI获取分组匹配:
route: "/user/{user}/{action}"
input: "/user/someone/news"
Run Code Online (Sandbox Code Playgroud)
什么是适当的正则表达式?在过去的几个小时里,我一直在寻找自己的酸...
我尝试过类似的东西,但没有结果:(
~\/app\/user\/(?P<user>[.*]+)\/(?P<action>[.*]+)~
Run Code Online (Sandbox Code Playgroud)
我在匹配数组中返回组,但没有基于组内输入的结果.
期望的输出:
Array
(
[0] => Array
(
[0] => "someone"
)
[user] => Array
(
[0] => "someone"
)
[1] => Array
(
[0] => "news"
)
[action] => Array
(
[0] => "news"
)
)
Run Code Online (Sandbox Code Playgroud)
通过一个例子澄清:
我的控制器有以下路由:/app/user/{username}/{action}
来自浏览器的请求URI是:/app/user/john/news
在捕获括号之间的变量时,如何使用正则表达式模式将该请求URI与该路由匹配?