English 中文(简体)
方括号内从括号中提取内容的真
原标题:True regex for getting content from parentheses in square brackets

I love/hate the regex because of usefulness/hardness. (I don t why but I can t construct pattern :( )
I have some records in my database field like this

[(ip1=192.x.?100)(id1=125485smds65)(date1=11.02.2011-1 5/15.06.2012-17:30)text1=Some text,其中可包括所有括号和(或)括号;任何果园等等;(案文}、[任何]{......]**) [(ip2=x.x.20.num)(2=12358(文本2=其他词):]

奥克,我希望返回一个具有价值阵列;

$result[ip1] = 192.x.?.100;
$result[id1] = 125485smds65;
$result[date1] = 11.02.2011-15:00/15.06.2012-17:30;
$result[text1] = Some text that can include all brackets and/or parentheses & any chars etc, like < ( text . } , [ any ) ] { etc.**;
$result[ip2] = 192.x.?.100;
$result[num2] = 1235845;
$result[text2] = many other words :)

您可以认为,括号内和括号中的数据数目可能有所不同。

因此,在收集上述数据之前,究竟是哪种情况?

最佳回答

类似情况:

$s =  (ip1=192.x.?.100)(id1=125485smds65)(date1=11.02.2011-15:00/15.06.2012-17:30)
(text1=Some text that can include all brackets and/or paranthesis & any chars etc, 
like < ( text . } , [ any ) ] { etc.**)][(ip2=x.x.20.?)(num2=1235845)
(text2=many other words :)) ;

preg_match_all( /((?:[^()]|(?R))*)/ , $s, $matches);

print_r($matches);

印刷:

Array
(
    [0] => Array
        (
            [0] => (ip1=192.x.?.100)
            [1] => (id1=125485smds65)
            [2] => (date1=11.02.2011-15:00/15.06.2012-17:30)
            [3] => (text1=Some text that can include all brackets and/or paranthesis & any chars etc, 
like < ( text . } , [ any ) ] { etc.**)
            [4] => (ip2=x.x.20.?)
            [5] => (num2=1235845)
            [6] => (text2=many other words :)
        )

)

in the regex patterns /(?:[^(>>>?R]/?

你们在问题下的评论清楚表明:在生产法典中不建议使用这种reg。 我的建议是而不是储存你的数据,就像你在你的数据库中所做的那样。 从根本上解决问题,请!

问题回答

你可以做到:

/((([^)=]*)=([^)]*)))*/

然而,这是不可能的“可以包括所有括号和(或)底线的一些案文”——在世界上,你如何将案文与封闭的括号区分开来?

And in case this is a very poor data structure. First of all it s a database - it has columns, use them! Second, why are you rolling your own datastructure? You can use json, or php s serialize().

劳动局是这项工作的错误工具。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...