Solr 4.x和SolrCloud(Solr 4.x and SolrCloud)
我不太清楚SolrCloud是单独的包还是Solr包的一部分(在4.x中)? 我正在阅读http://wiki.apache.org/solr/SolrCloud 。 最初我认为SolrCloud是一个单独的包,但是当我通过维基页面阅读时,我得到的印象是SolrCloud是Solr包的一部分?
如果有人能澄清,那将是伟大的。
It is not very clear to me whether SolrCloud is a separate package or a part of Solr package (in 4.x)? I was reading http://wiki.apache.org/solr/SolrCloud. Initially I thought SolrCloud is a separate package but as I read thru the wiki page, I got an impression that SolrCloud is a part of the Solr package?
If someone could clarify, that will be great.
原文:https://stackoverflow.com/questions/17637077
最满意答案
不太确定你在这里尝试了什么,但是如果我要制作一个与单词列表匹配的正则表达式(或者根据具体情况可能是函数名称),我会做类似的事情。
// add/remove allowed stuff here $allowed = array( 'nl2br', 'substr', 'addslashes' ); // make the array into a branching pattern $allowed_pattern = implode('|', $allowed); // the entire regexp (a little stricter than yours) $pattern = "/\{function=\"($allowed_pattern)\((.*?)\)\"\}/"; if( preg_match($pattern, $string, $matches) ) { # string DOES contain an allowed function # The $matches things is optional, but nice. $matches[1] will be the function name, and # $matches[2] will be the arguments string. Of course, you could just do a # preg_replace_callback() on everything instead using the same pattern... } else { # No allowed functions found }
$allowed
数组使得添加/删除允许的函数名称变得更容易,并且regexp对于大括号,引号和一般语法更加严格,这可能是一个好主意。但首先,翻转if..else分支,或使用
!
。preg_match
用于匹配字符串中的东西,而不是用于匹配那里不存在的东西。 所以你不能真正让它回归那些不存在的东西尽管如此,正如Álvaro所提到的,正则表达式可能并不是解决这个问题的最佳方式,而且无论代码的其余部分如何,将函数暴露出来都是非常危险的。 如果你只是需要匹配单词它应该工作正常,但因为它的函数调用任意参数......好吧。 我不能真的推荐它:)
编辑:第一次,我
preg_quote
爆字符串上使用preg_quote
,但这当然只是转义管道字符,然后模式将无法工作。 所以跳过preg_quote
,但是请确保函数名称不包含任何可能搞乱最终模式的内容(例如, 在插入数组之前通过preg_quote
运行每个函数名称)Not quite sure what you're trying here, but if I were to make a regexp that matched a list of words (or function names as the case may be), I'd do somthing like
// add/remove allowed stuff here $allowed = array( 'nl2br', 'substr', 'addslashes' ); // make the array into a branching pattern $allowed_pattern = implode('|', $allowed); // the entire regexp (a little stricter than yours) $pattern = "/\{function=\"($allowed_pattern)\((.*?)\)\"\}/"; if( preg_match($pattern, $string, $matches) ) { # string DOES contain an allowed function # The $matches things is optional, but nice. $matches[1] will be the function name, and # $matches[2] will be the arguments string. Of course, you could just do a # preg_replace_callback() on everything instead using the same pattern... } else { # No allowed functions found }
The
$allowed
array makes it easier to add/remove allowed function names, and the regexp is stricter about the curly brackets, quotes and general syntax, which is probably a good idea.But first of all, flip the if..else branches, or use a
!
.preg_match
is meant for, well, matching stuff in the string, not for matching stuff that isn't in there. So you can't really get it to returntrue
for something that isn't thereStill, as Álvaro mentioned, regexps probably aren't the best way to go about this, and it is pretty risky to have functions exposed like that, no matter the rest of the code. If you just needed to match words it should work fine, but since it's function calls with arbitrary arguments... well. I can't really recommend it :)
Edit: First time around, I used
preg_quote
on the imploded string, but that of course just escapes the pipe characters, and then the pattern won't work. So skippreg_quote
, but then just be sure that function names don't contain anything that might mess up the final pattern (e.g. run each function name throughpreg_quote
before imploding the array)
相关问答
更多-
从我所看到的,你根本不需要preg_match 。 然而,你遇到的问题是逃避。 你有这个: "/[a-zA-Z]\\_[a-zA-Z]/" 您已经正确识别出需要转义反斜杠,但是,您错过了一个微妙的问题: PHP中的正则表达式是字符串。 这意味着您需要将其作为字符串和正则表达式进行转义。 实际上,这意味着要正确地转义反斜杠以使其与模式中的实际反斜杠字符匹配,实际上需要有四个反斜杠。 "/[a-zA-Z]\\\\_[a-zA-Z]/" 它不漂亮,但就是这样。 希望有所帮助。 You don't really ...
-
php regex preg_match(php regex preg_match)[2022-12-03]
你可以使用这个正则表达式 \w+(-\w+){3,} \w类似于[a-zA-Z0-9_] \w+匹配1到多个字符 {3,}是一个量词,它匹配前面的组3到很多次 You can use this regex \w+(-\w+){3,} \w is similar to [a-zA-Z0-9_] \w+ matches 1 to many character {3,} is a quantifier that matches preceding group 3 to many times -
使用php preg_match(using php preg_match)[2023-01-01]
正则表达式工作正常 。 你错过了分隔符吗? 该函数应该像这样使用: preg_match('/[0-9\.]+/', $string, $result); (顺便说一句,你不需要在字符类中转义。 [0-9.]就足够了。) The regex works fine. Are you missing the delimiters? The function should be used like this: preg_match('/[0-9\.]+/', $string, $result); (BTW, ... -
来自html的php preg_match(php preg_match from html)[2024-03-30]
尝试更简单的事情: $regex = "/Disponible:\D+(\d+)/"; preg_match($regex,$string,$match); var_dump($match[1]); 正则表达的力量源于它们的灵活性。 Try something much simpler: $regex = "/Disponible:\D+(\d+)/"; preg_match($regex,$string,$match); var_dump($match[1]); The power of regexe ... -
尝试下面的代码: $value = '123-123-123-12345'; if(preg_match("/^[0-9]{3}\-[0-9]{3}\-[0-9]{3}\-[0-9]{5}+$/", $value)) { echo "Yeah match Elm: ".$value."
"; } else { echo "Boo Hoo Elm: '".$value."'
"; } (不确定\是否有用 - 但在这种情况下它们似乎不会造成任何麻烦) 我得到: Ye ... -
对于具体的链接 /http:\/\/[a-zA-Z]{3}\.[a-zA-Z]{2}\/[a-zA-Z]{7}\/[a-zA-Z]{6}\/\d{12}/ 在线测试 - > http://www.functions-online.com/preg_match.html 如果你想了解我做了什么(在页面底部是一个备忘单) http://regex101.com/ ps:这个模式只适用于你提供的链接,可以'保证其他人可以工作,阅读备忘单 for the concrete link /http:\/\/[a-zA- ...
-
解决方案 我首先从字符串中删除所有特殊字符和数字,然后使用字边界匹配单词: $cleaned = preg_replace('/[^a-z ]+/i', '', 'This is dem*#o text, contains de12mo3 text, is .demo23* text'); preg_match_all('/\bdemo\b/i', $cleaned, $matches, PREG_OFFSET_CAPTURE); var_dump($matches); 会给你( Codepad De ...
-
php preg_match噩梦(php preg_match nightmare)[2022-09-25]
$pattern = "%(\d+) */ *(\d+)%"; $test = array( 'half is 1/2', '13/100 is your score', 'only 23 /90 passed', 'no idea here:7/ 123', '24 / 25', '1a/2b' ); foreach($test as $t){ if(preg_match($pattern, $t, $matches)) echo ... -
PHP,Regex和preg_match(PHP, Regex and preg_match)[2023-01-20]
使用preg_match_all获取所有匹配项。 preg_match只会返回第一个匹配项。 Count将返回两个因为您捕获一个组。 Use preg_match_all to get all matches. preg_match will only return the first match. Count will return two because you capture a group. -
不太确定你在这里尝试了什么,但是如果我要制作一个与单词列表匹配的正则表达式(或者根据具体情况可能是函数名称),我会做类似的事情。 // add/remove allowed stuff here $allowed = array( 'nl2br', 'substr', 'addslashes' ); // make the array into a branching pattern $allowed_pattern = implode('|', $allowed); // the entire reg ...