+ -
当前位置:首页 → 问答吧 → 正则表达式如何写?{ordinary|normal|regular|standard}

正则表达式如何写?{ordinary|normal|regular|standard}

时间:2011-12-16

来源:互联网

{ordinary|normal|regular|standard}
以上用正则表达式写出,花括号中间内容只能是字母,空格,|,主要是查出两边的花括号{};
请问这种表达式怎么写?

作者: dhc_1229   发布时间: 2011-12-16

乔丹会爱抚你...我就打个酱油得了

作者: PhpNewnew   发布时间: 2011-12-16

very ordinary-looking women{regular|standard}wired phenomenon in the job{market|marketplace}but in most of
 还有以上
}wired phenomenon in the job{
}……{ 中间内容不能有花括号
这个一段的正则又该怎么写?

作者: dhc_1229   发布时间: 2011-12-16

PHP code
<?php
    $str = 'asdfefefefefef{ordinary|normal|regular|standard}';
    $patten = '/(\{[ a-z|]+\})/i';
    preg_match_all($patten,$str,$matches);
    print_r($matches);

作者: ohmygirl   发布时间: 2011-12-16

PHP code
<?php
    $str = 'very ordinary-looking women{regular|standard}wired phenomenon in the job{market|marketplace}but in most of';
    $patten = '/\}([^{]+)\{/i';
    preg_match_all($patten,$str,$matches);
    print_r($matches);

作者: ohmygirl   发布时间: 2011-12-16

PHP code

$STR = 'very ordinary-looking women{regular|standard}wired phenomenon in the job{market|marketplace}but in most of';
preg_match_all('/\{[a-z\s|]+\}/isU', $STR, $matches);
print_r($matches);
/**
输出结果:
Array ( [0] => Array ( [0] => {regular|standard} [1] => {market|marketplace} ) ) 
*/

作者: yangball   发布时间: 2011-12-16

引用 3 楼 ohmygirl 的回复:

PHP code
<?php
$str = 'asdfefefefefef{ordinary|normal|regular|standard}';
$patten = '/(\{[ a-z|]+\})/i';
preg_match_all($patten,$str,$matches);
print_r($matches);

为什么输出了两边?

作者: dhc_1229   发布时间: 2011-12-16

引用 6 楼 dhc_1229 的回复:

引用 3 楼 ohmygirl 的回复:

PHP code
<?php
$str = 'asdfefefefefef{ordinary|normal|regular|standard}';
$patten = '/(\{[ a-z|]+\})/i';
preg_match_all($patten,$str,$matches);
print_r($matches);

为什么输……


不是两遍。
匹配的结果保存在$matches[1]中

作者: ohmygirl   发布时间: 2011-12-16

引用 7 楼 ohmygirl 的回复:

引用 6 楼 dhc_1229 的回复:

引用 3 楼 ohmygirl 的回复:

PHP code
<?php
$str = 'asdfefefefefef{ordinary|normal|regular|standard}';
$patten = '/(\{[ a-z|]+\})/i';
preg_match_all($patten,$str,$matches);
pr……


那就是对的,有没有学习正则表达式好的资料啊?

作者: dhc_1229   发布时间: 2011-12-16

引用 8 楼 dhc_1229 的回复:

引用 7 楼 ohmygirl 的回复:

引用 6 楼 dhc_1229 的回复:

引用 3 楼 ohmygirl 的回复:

PHP code
<?php
$str = 'asdfefefefefef{ordinary|normal|regular|standard}';
$patten = '/(\{[ a-z|]+\})/i';
preg_match_all($pa……


个人推荐 精通正则表达式 ,通俗易懂。

作者: ohmygirl   发布时间: 2011-12-16