[英]regex to match a multi-line string
Sorry, for the badly named topic. 对不起,这个名字不好用。 I'm looking for a efficient regular expression to match the following:
我正在寻找一个有效的正则表达式来匹配以下内容:
[2014-11-13 13:05:04] [path/to/class.instagram.php] Options: array (
'client_id' => '',
'client_secret' => '',
'object' => 'tag',
'object_id' => 'rwar',
'aspect' => 'media',
'callback_url' => 'http://www.localthisday.nl/instagram.callback.php',
)
I want it to be split up so it looks like this: 我希望将其拆分成这样:
1. [2014-11-13 13:05:04]
2.[path/to/class.instagram.php]
3. Options: array (
'client_id' => '',
'client_secret' => '',
'object' => 'tag',
'object_id' => 'rwar',
'aspect' => 'media',
'callback_url' => 'http://www.localthisday.nl/instagram.callback.php',
)
I'm using this one at the moment: 我目前正在使用这个:
(\\[(.*)\\])(\\s{1})(\\[(.*)\\])(\\s{1})(.*)/gmi
I know, it's not a very good one, that's probably why it doesn't work the way I want it to work. 我知道,这不是很好,这可能就是为什么它无法按我希望的方式工作的原因。 Problem is;
问题是; it's a multi-line string, and for some reason it does not work multi-line.
它是多行字符串,由于某种原因,它不能用于多行。 Could someone please help me?
有人可以帮我吗? I'm not that good in regular expressions unfortunately.
不幸的是,我的正则表达式不好。
使用非贪婪量词:
(\[.*?\])\s(\[.*?\])\s(.*)/gmi
(\]|\))
Try this.Replace by $1\\n
.See demo. 试试这个,用
$1\\n
代替,看演示。
http://regex101.com/r/pQ9bV3/32 http://regex101.com/r/pQ9bV3/32
var re = /(\]|\))/gm;
var str = '[2014-11-13 13:05:04] [path/to/class.instagram.php] Options: array (\n \'client_id\' => \'\',\n \'client_secret\' => \'\',\n \'object\' => \'tag\',\n \'object_id\' => \'rwar\',\n \'aspect\' => \'media\',\n \'callback_url\' => \'http://www.localthisday.nl/instagram.callback.php\',\n)';
var subst = '$1\n';
var result = str.replace(re, subst);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.