草庐IT

Preg_Match

全部标签

php - 为什么\\。平等的\。在preg_replace?

在top-votedanswer至thisfantasticquestion,以下正则表达式用于preg_replace调用(来自答案的auto_version函数):'{\\.([^./]+)$}'这个正则表达式的最终目标是从给定的文件名中提取文件的扩展名。但是,我对为什么这个正则表达式的开头起作用感到困惑。即:为什么\\.匹配方式与\.相同在正则表达式中?前者不应该匹配(a)一个文字反斜杠,后跟(b)任何字符,而第二个匹配一个文字句点吗?singlequotedstrings的规则说明\\产生文字反斜杠。考虑这个简单的例子:$regex1='{\.([^./]+)$}';//Var

php - 警告 : preg_match(): Compilation failed: unrecognized character after (? 或 (?-

我有一个以前的程序员编写的代码,一个抛出编译错误的正则表达式preg_match:$regex_t="/".$op."(?\\>[^".$op.$cl."]+)*".$cl."/s";preg_match($regex_t,$text,$inner);我收到的警告是:Warning:preg_match():Compilationfailed:unrecognizedcharacterafter(?or(?-atoffset4另外,我想提一下var_dump($regex_t)的值是:string'/\{(?\>[^\{\}]+)*\}/s'(length=21)

php - 删除除最后一个逗号之外的逗号 w preg_replace

我头晕目眩,我试着自己做这个,但想不通。所以我将再次求助于你们的知识。这些都是我可能的字符串:Myheadisspinningwith,pregreplaceMyheadisspinning,with,pregreplaceMyheadis,spinning,with,pregreplaceMyhead,is,spinning,with,pregreplace(注意上面字符串中的逗号)我希望所有“preg-replaced”/“string-replaced”最后只有一个逗号。(就像第一个示例中显示的那样)我的头在旋转,pregreplace提前致谢;) 最

php - 我的正则表达式出了什么问题?

preg_match('/[^0-9A-Za-z/._\-\s]/',$user)我得到了Warning:preg_match()[function.preg-match]:Unknownmodifier'.'inF:\wamp\www\distinctive\include\validate.inc.phponline4为什么? 最佳答案 您需要转义正则表达式中的/:preg_match('/[^0-9A-Za-z\/._\-\s]/',$user)或使用不同的分隔符:preg_match('#[^0-9A-Za-z/._\-\s

php - 使用 preg_match 检查字符串是否仅包含 A-Z、a-z 和 -(破折号)字符

这个问题在这里已经有了答案:Needaregexthatwillcheckifthestringonlyconsistlettersa-zandnumbersandunderscore(_)andhyphen(-)(5个答案)关闭9年前。我试过:print_r(preg_match("[A-Za-z\\-]",$str));我越来越假了。我不太擅长正则表达式,但它似乎适用于http://regexpal.com/我是不是漏掉了什么?编辑:例如$str=zREBsZtyvw

php - preg_match编译失败:字符类中的无效范围

这个问题已经有了答案:preg_match():Compilationfailed:invalidrangeincharacterclassatoffset4答我使用laravel作为框架,并尝试使用自己的preg_match函数来验证表单。以下是我的代码:Validator::extend('alpha_num_spaces',function($attribute,$value){returnpreg_match('/^([-a-z0-9_-\s])+$/i',$value);});现在,我已经在生产服务器上运行了这个程序,它运行得很好,但是,在我的本地计算机上,我收到:preg_

php - 将 array_key_exists 与 preg_match 结合使用

我正在尝试根据模式确定一个或多个匹配项是否存在于数组中,数组的例子:Array([author_id]=>1[channel_id]=>1[site_id]=>1[entry_id]=>6[url_title]=>test_title_with_file2[title]=>TestTitlewithfile[field_id_1_directory]=>1[field_id_4_directory]=>1[submit]=>Submit[entry_date]=>1278219110)我想确定field_id_x_directory键或多个键是否存在,如果存在,则循环遍历每个键并运行一

php - preg_match 错误 : Compilation failed: missing terminating ] for character class

我在for循环中读取了一系列.txt文件。我在一些文本文件中放置了一个token,格式为[widget_]因此,例如,文本文件的全部内容可能是[widget_search]。另一个文本文件可能包含内容[widget_recent-posts]。其他人可能只有html格式的文本,根本没有token。在for循环中,我正在执行preg_match以查看文本文件的内容是否与我的标记模式匹配。如果匹配,我将执行一些条件代码。但是,当我运行跟踪测试以查看是否存在匹配时出现错误。错误是:警告:preg_match()[function.preg-match]:编译失败:在C:\xampplite\

PHP - preg_match - 如何将字符串的大写/小写与它之前或之后的任何内容相匹配?

我有一个函数的一部分是这样的:if(preg_match("#\bscript\b#",$userInput)){$bannedWord='script';logHax();returnTRUE;}这导致了我试图完成的问题,因为它只会匹配确切的单词“script”,而不匹配它的变体,如“ScriPt”或“”。我想要的是不匹配字符串的示例以及原始字符串返回true。 最佳答案 怎么样:if(preg_match("/]*>/i",$userInput)){$bannedWord='script';logHax();returnTRUE

php - 如何将可变模式与 preg_match 一起使用?

我不知道这些数据是否足够,但我有preg_match('/SAMPLETEXT/',$bcurl,$cookie1);我想知道我能不能做到这一点preg_match($newfunction,$bcurl,$cookie1);但是当我这样做时,我收到此错误“警告:preg_match()[function.preg-match]:定界符不能是字母数字或反斜杠”。如何让它检查我的新函数,而不是只检查“SAMPLETEXT”。 最佳答案 尝试preg_match("/$newfunction/",$bcurl,$cookie1);以便您