标签: preg-match-all

preg_match_all 不匹配所有可能性

我正在尝试检索所有匹配项,但我只收到一个

这是我的字符串

$html = '<p> This is my Home Page.</p><p><span style="line-height: 1.42857;">{{ type="slider" }} </span></p><p> </p>';
Run Code Online (Sandbox Code Playgroud)

如果你看到 string contains {{ type="slider" }} ,现在如果我只写一次这个字符串,我就得到了预期的结果,但是如果我在 html 中多次写它,就像 {{ type="slider" }} {{ type="banned" }} {{ type="testimonial" }}

$html = '<p> This is my Home Page.</p><p><span style="line-height: 1.42857;">{{ type="slider" }} {{ type="banner" }} {{ type="testimonial" }}  </span></p><p> </p>';
Run Code Online (Sandbox Code Playgroud)

并尝试获取我的字符串中的值,{{ type=" ???? " }}它显示奇怪的结果

我正在使用下面的代码。

preg_match_all('/{{ type=\"(.+)\" }}/', $html, $matches, PREG_SET_ORDER);
echo "<pre>";
print_r($matches);
foreach ($matches as $val) {
    echo "matched: …
Run Code Online (Sandbox Code Playgroud)

php regex preg-match-all

1
推荐指数
1
解决办法
1164
查看次数

从字符串中提取 5 或 6 位数字

我正在尝试仅从字符串中提取 5 或 6 位数字。下面是我尝试过的代码,但它不符合预期。

$str1 = "21-114512"; //it should return 114512      
$str2 = "test12345abcd"; //it should return 12345   
$str3 = "12test123456testing"; //it should return 123456    

function extract_numbers($string)
{
   preg_match_all('/\b[^\d]*\d{6}[^\d]*\b/', $string, $match);

   return $match[0];
}

print_r(extract_numbers($str1));
Run Code Online (Sandbox Code Playgroud)

php regex extract digits preg-match-all

1
推荐指数
1
解决办法
2698
查看次数

PHP正则表达式找到@someone

我需要在PHP中使用常规表达式,我可以插入preg_match_all并查找@符号和任何字符编号或字母后面是否紧随其后.

所以如果我放

@patrick你好

如果我投入,它会成真

"我在商场看到她了"

这将是错误的.

谢谢

php regex preg-match-all

0
推荐指数
1
解决办法
91
查看次数

在我想要实际匹配之后停止匹配*所有*的正则表达式!

我对整个正则表达式的事情都很陌生并试图preg_match_all在PHP中做一个我想要的结果,但问题是它我真正想要之后匹配所有内容......就像这样:

字符串:This is something <code>Some code here</code> and more 来自正则表达式的<code>Some code here</code> and more 匹配:来自正则表达式的通缉比赛:<code>Some code here</code>

这是我正在使用的正则表达式: /<code>(.*)<\/code>/

我认为这与开始和结束/分隔符有关,但我不完全确定.

任何帮助将不胜感激,谢谢!

php regex preg-match-all

0
推荐指数
1
解决办法
2882
查看次数

警告:preg_match_all()[function.preg-match-all]:未知修饰符'g'

错误:

警告:preg_match_all()[function.preg-match-all]:第23行/Users/julian/Sites/abc.php中的未知修饰符'g'警告:preg_match_all()[function.preg-match-all]:未知第23行/Users/julian/Sites/abc.php中的修饰符'g'

这是我的代码:

<?php

class Crawler {
protected $markup = ”;
    public function __construct($uri) {
        $this->markup = $this->getMarkup($uri);
    }
    public function getMarkup($uri) {
        return file_get_contents($uri);
    }
    public function get($type) {
        $method = "_get_links";
        if (method_exists($this, $method))
                return call_user_method($method, $this);
             }
    }
    protected function _get_images() {
        if (!empty($this->markup)){
            preg_match_all(htmlspecialchars("<img([^>]+)/>i"), $this->markup, $images);
            return $images[1];
    }
    }
    protected function _get_links() {
        if (!empty($this->markup)){
            preg_match_all(htmlspecialchars("<a([^>]+)>(.*?)</a>/i"), $this->markup, $links);
            return $links;
        }
    }
}
$crawl = new Crawler("http://google.com/");
$images = $crawl->get(‘images’);
$links = $crawl->get(‘links’);
echo $links; …
Run Code Online (Sandbox Code Playgroud)

php preg-match-all

0
推荐指数
1
解决办法
3554
查看次数

我应该使用哪种模式与preg_match_all()来提取此字符串中的金额?

想要在以下字符串中提取金额:

£5000 per Night - 1 bedroom - Serviced Apartment
Run Code Online (Sandbox Code Playgroud)

关于如何使用preg匹配所有的想法?

我正在使用这种模式:

preg_match_all("|£(\d)|U",$string,$matches);
Run Code Online (Sandbox Code Playgroud)

但它只取5而不是5000

如果用15,000英镑可以用逗号提取它怎么办?

thx的帮助,

斯特凡

php regex preg-match-all

0
推荐指数
1
解决办法
82
查看次数

如何在正则表达式中使用常量或var的preg_match/preg_match_all?

我有以下模式:

preg_match( "/^(.*?\/wp-content\/)([^\?]+)(.*)$/", $src, $src_bits );
Run Code Online (Sandbox Code Playgroud)

现在我想设置wp-content一个WP_CONTENT_FOLDERNAME包含文件夹名称的常量.我该怎么办?

php constants preg-match-all preg-match

0
推荐指数
1
解决办法
1262
查看次数

正则表达式PHP preg_match_all

我是一个自我思考的PHP初学者,我还在学习正则表达式.这是我遇到的问题preg_match_all和数组

我的数组有完整的以下信息:

;;CARLOS||ANDREW||STEPH||SUE||JUDY||HAROLD||JAMES||KATIE||JESSICA;;
Run Code Online (Sandbox Code Playgroud)

我要做的是单独显示每个名称,大约有250个不同的名称,数组总是以;; 并始终以;;结尾; 所以这是我的问题,首先我的数组加载正常但只做第一个名称:

    preg_match_all('/^(.+?)\|\|/', $body, $part);
    foreach ($part[1] as $part){
    print_r($part);
Run Code Online (Sandbox Code Playgroud)

结果是 ;;CARLOS

$body巨大的名称列表在哪里(包含250多个名称的数组).

期望的结果:

CARLOS
ANDREW
STEPH
JUDY
HAROLD
JAMES
KATIE
JESSICA
Run Code Online (Sandbox Code Playgroud)

请理解我无法更改输入数组,它就是它.所以基本上在第一个数组我已加载整个列表然后我需要打破它| 字符.

谢谢你的建议.

php arrays preg-match-all

0
推荐指数
1
解决办法
136
查看次数

preg_match_all:警告:preg_match_all():未知修饰符'('in

可能重复:
preg_match()未知修饰符'['帮助

我想要匹配这种模式

 $regex_pattern = '<td id="(\w+)" class="(\w+)">(\w+).com<\/td>';
 preg_match_all($regex_pattern, $result, $matches);
 print_r($matches);
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:警告:preg_match_all():未知修饰符'('in

我的正则表达式模式有什么问题?

php regex preg-match-all preg-match

0
推荐指数
1
解决办法
5211
查看次数

PHP preg_match_all动态删除url参数

我想只获取没有任何参数的url的"清洁"版本.IOW ...如果网址内有问号,请将其删除,然后删除所有内容.

这是我目前的行:

preg_match_all('/<a(.*?)href=("|\'|)(.*?)("|\'| )(.*?)>/s',$content,$ahref);
Run Code Online (Sandbox Code Playgroud)

而且在这里要更清楚......我期待这个网址(例如):

/go/page/mobile_download_apps.html?&who=r,6GDewh28SCW3/fUSqmWqR_E9ljkcH1DheIMqgbiHjlX3OBDbskcuCZ22iDvk0zeZR7BEthcEaXGFWaQ4Burmd4eKuhMpqojjDE6BrCiUtLClkT32CejpMIdnqVOUmWBD
Run Code Online (Sandbox Code Playgroud)

将会 :

/go/page/mobile_download_apps.html
Run Code Online (Sandbox Code Playgroud)

php regex string preg-match-all preg-match

0
推荐指数
1
解决办法
138
查看次数

标签 统计

php ×10

preg-match-all ×10

regex ×7

preg-match ×3

arrays ×1

constants ×1

digits ×1

extract ×1

string ×1