正则表达式 – Smarty正则表达式匹配
发布时间:2020-12-14 05:55:56 所属栏目:百科 来源:网络整理
导读:我有一个聪明的变量,我想知道它是否匹配某些字符串 "whatever_thestring_whatever" 在哪里 whatever表示任何字符序列(或没有字符). 有没有办法测试像* _thestring_ *这样的东西? 解决方法 使用smarty检查另一个字符串中是否存在字符串: {assign "haystack1
我有一个聪明的变量,我想知道它是否匹配某些字符串
"<whatever>_thestring_<whatever>" 在哪里< whatever>表示任何字符序列(或没有字符). 有没有办法测试像* _thestring_ *这样的东西? 解决方法
使用smarty检查另一个字符串中是否存在字符串:
{assign "haystack1" "whatever_thestring_whatever"} {assign "haystack2" "whatever_thestrings_whatever"} Test haystack1 {if $haystack1|strstr:"_thestring_"}Found!{/if}<br /> Test haystack2 {if $haystack2|strstr:"_thestring_"}Found!{/if}<br /><br /> 输出: Test haystack1 Found! Test haystack2 或者你可以在smarty中使用Regex进行更复杂的搜索: {assign "haystack1" "whatever_thestring_whatever"} {assign "haystack2" "whatever_thestrings_whatever"} {assign "check_haystack1" $haystack1|regex_replace:"/_thestring_/":" "} {assign "check_haystack2" $haystack2|regex_replace:"/_thestring_/":" "} Test haystack1 {if $check_haystack1 !== $haystack1}Found!{/if}<br /> Test haystack2 {if $check_haystack2 !== $haystack2}Found!{/if}<br /> 哪个有输出: Test haystack1 Found! Test haystack2 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |