字符串内容
abc def ghi jkl mno
{abc def ghi jkl mno}
abc def ghi jkl mno
{abc def ghi jkl mno}用正规表达式怎样把{}之外内容中的def替换成opq,jkl替换成mno?查找{}之间内容的表达式可以用"(\{)(\r\n)*(.*)(\})"
abc def ghi jkl mno
{abc def ghi jkl mno}
abc def ghi jkl mno
{abc def ghi jkl mno}用正规表达式怎样把{}之外内容中的def替换成opq,jkl替换成mno?查找{}之间内容的表达式可以用"(\{)(\r\n)*(.*)(\})"
解决方案 »
- ★★★大家给我推荐一份工作吧
- 用telnet发送邮件,怎样结束输入
- 关于临界区的的简单问题
- 我写一个钩子程序在xp下运行正常,到了2k下就不正常了 请大家帮我看看 谢谢:)!
- 请问如何向对话框添加滚动视图和普通视图,我不知道滚动视图和普通视图的类名称是什么?
- 登陆界面设计问题?
- #pragma comment(lib,"Ws2_32.lib")
- 如何在SDI中动态创建ListBox控件?
- 怎么使clistbox和clistctrl的滚动条自动滚动并显示listbox或listctrl中的最后一条数据?
- 请问类中静态成员函数与普通静态成员函数的区别
- 小女子这厢有理了,请教关于监测网络通断的问题
- 如何自定义控件的事件响应函数?
char *token;
/* Get the first token: */
token = strtok( strLsh, seps );
{
}
/* Get next token: */
token = strtok( NULL, seps );
正规表达式好像是用来定义文法的,不是用来替换什么东西的。你是想用Lex作吗?拜托你说清楚点
$bbcode = preg_replace("/(\[)({)(])(\r\n)*(.*)(\[\/}\])/esiU", "\\2", $bbcode);那我再说一次我的要求
字符串内容:
abc def ghi jkl mno
{abc def ghi jkl mno}
abc def ghi jkl mno
{abc def ghi jkl mno}用正规表达式怎样把{}之外内容中的def替换成opq,jkl替换成mno?
替换的结果如下:
abc opq ghi mno mno
{abc def ghi jkl mno}
abc opq ghi mno mno
{abc def ghi jkl mno}
^[^{]def^[$}]/opq
^[^{]def^[$}]/opq我试了,不行。
$s = "abc def ghi jkl mno
{abc def ghi jkl mno}
abc def ghi jkl mno
{abc def ghi jkl mno}
";
$patterns = array(
"/([^{]*)def([^}]*)/",
"/([^{]*)jkl([^}]*)/"
);
$replace = array(
"\\1opg\\2",
"\\1mno\\2"
);
echo preg_replace($patterns,$replace,$s);
?>
function rep(s)
{
if (s.toLowerCase() == "def")
return "opq";
else if (s.toLowerCase() == "jkl")
return "mno";
else
return s;
}s = "abc def ghi jkl mno \n{abc def ghi jkl mno} \nabc def ghi jkl mno \n{abc def ghi jkl mno}";
re = /\b(def|jkl)\b(?=[^{}]+\{)/gmi;
s = s.replace(re, function(){ return rep(arguments[0]);});
alert(s);
</script>
<?php
$s = "abc def ghi jkl mno
{abc def ghi jkl mno}
abc def ghi jkl mno
{abc def ghi jkl mno}
";
$patterns = array(
"/([^{]*)def([^}]*)/",
"/([^{]*)jkl([^}]*)/"
);
$replace = array(
"\\1opg\\2",
"\\1mno\\2"
);
echo preg_replace($patterns,$replace,$s);
?>要是分隔符{变成[code],}变成[/code],那应该怎样变呢?
我只在perl 和 php里面学过
$searcharray = array("/([^\x80]*)asdf([^\x81]*)/i");
$replacearray = array("\\1凌萍\\2");怎样替换全部