谁能帮我写个正则表达式 大写字母

谁来帮我写一个正则表达式啊?
我需要提取模板 ${} 的 key,不会写,示例如下:
abc${快帮帮我}ac${你真好}23${thankyou}
快帮帮我&你真好 &thankyou
http://tool.oschina.net/regex
元数据:abc${快帮帮我}ac${你真好}23${thankyou}
正则表达式:[^$^{^}]+}
匹配结果:
共找到 3 处匹配:
--- 共有 1 条评论 ---
已解决了~谢谢
String str = "abc${快帮帮我}ac${你真好}23${thankyou}";
Pattern p = pile("\\$\\{(.*?)\\}");
Matcher m = p.matcher(str);
while (m.find()) {
System.out.println(m.group(1));
--- 共有 3 条评论 ---
Pattern p = pile("\\$\\{(.*?)\\}");
非常感谢~~~采纳了~以后得花时间学学正则了~~~
获取${}的内容 & &\$\{.*?\}
然后把${}删了
--- 共有 1 条评论 ---
谢谢给的建议~~
String str = "abc${快帮帮我}ac${你真好}23${thankyou}";
System.out.println(str.replaceAll(".*?\\$\\{(.*?)\\}.*?", "$1"));
--- 共有 1 条评论 ---
谢谢,已经能替换了,我想把 每个${} 内容
分别提取出来要怎么做??现在是 整个字符串
要取{}里的 &但是别的地方也有字母 &建议先连{}一起先取出来然后截取&
{[\u4e00-\u9fa5A-Za-z]*}
--- 共有 2 条评论 ---
谢谢~我想直接提取到 里面的内容,我再改改看
/othertools/regex/
正则验证地址
my $r = '\$\{(.*?)\}';
my $str = 'abc${快帮帮我}ac${你真好}23${thankyou}';
print $1 while($str =~ /$r/g);
--- 共有 1 条评论 ---
还有层${} 还在,我想直接提取出里面的内容 我再试试哈...谢谢~~~中国Java开发网 - 求一个正则表达式,我写出来的不是我想要的:(
中国Java开发网
您没有登录
»&&»&
因为只能够靠正则表达式把某个元素信息去掉。但是我写的却有问题。代码如下:
String strtest="&msgs&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
"&&&msg&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
System.out.println(strtest.replaceAll("&Content&.*&/Content&","\n"));执行结果为:&msgs&&msg&
&Title&asassasa&/Title&
&/msgs&而我真正需要的结果是:&msgs&&&&msg&&&&&&Title&asassasa&/Title&&&&/msg&&&&msg&&&&&&Title&asassasa&/Title&&&&/msg&&&&msg&&&&&&Title&asassasa&/Title&&&&/msg&&&&msg&&&&&&Title&asassasa&/Title&&&&/msg&&/msgs&请帮忙改改这个正则表达式,谢谢!!!
bluepure edited on
晕,这里的正则表达式也有问题,我代码之间有说话了的,却看不到 :(要Ctrl+A才能够看见。
发贴: 4629
RE is greedy, I don't know whether we can make it non-greedy with replaceAll.
Please check the API.
不是好好的,那来的看不见?
发贴: 3233
why did something?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler, Refactoring - Improving the Design of Existing Code
发贴: 4629
BTW, the "non-greedy" "quantifier" is the question mark, i.e. for your example, it should be
System.out.println(strtest.replaceAll("&Content&.*?&/Content&","\n"));However, I'm not sure whether Java's RE supports this or not -- it should but I'm not 100% sure and am lazy to check. floater: both 而我真正需要的结果是:and 请帮忙改改这个正则表达式,谢谢!!! were invisible,but when I tried to correct them a moment ago, they seemed to be okay.
Anway, I still pressed the Change button.
why edited on
netboy wrote:不是好好的,那来的看不见?刚才我自己改了一下(就是在内容里添了几个回车),就成下面的样子了麻烦why 帮我改回来,谢谢!!!
(缩略图,点击图片链接看原图)
to why :经过测试,已经可用,谢谢!!!
发贴: 4629
It displays okay on Mozilla, seems to be a bug with IE when there's an extra &BR& before &/PRE&
String strtest="&msgs&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
&Title&asassasa&/Title&"+
&Content&cccccccc&/Content&"+
System.out.println(strtest.replaceAll("&Content&.*&/Content&","\n"));Extra newline beneath执行结果为:&msgs&&msg&
&Title&asassasa&/Title&
&/msgs&No newline beneath而我真正需要的结果是:&msgs&
&Title&asassasa&/Title&
&Title&asassasa&/Title&
&Title&asassasa&/Title&
&Title&asassasa&/Title&
&/msg&&/msgs&Extra newline and a space beneath Hello!
why edited on
发贴: 3233
yep, ok with firefox and not in IE.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler, Refactoring - Improving the Design of Existing Code
Actually, i met this kind of problem before. Pay special attention when using .*. Cause the standard quantifiers are greedy,and this end up the RE goes all the way to the end of string to get the last match(The reason why getting unexpected result).Using Lazy Quantifiers, for example, .*? can solve the problem mentioned above. These are avanced topics for regular expression. You can study this field by reading the book of Master Regular Expression.For the return (\n), i remember i use "\\\\n" instead. In addition, i wonder if we can use System.getProperty("line.separator") to solve the platform dependent problem.
jameszhang
CJSDN高级会员
发贴: 1594
bluepure wrote:请帮忙改改这个正则表达式,谢谢!!!这样是不System.out.println(strtest.replaceAll("&Content&[a-z]*&/Content&", "\n"));
why edited on
"First they ignore u, then they laugh at u, then they fight u, then u will winMahatma Gandhi"
正则表达式的贪婪性造成的,呵呵。regTest=/&Content&[^&]*&\/Content&/g;因为中间部分需要不包含&号的
发贴: 4629
syvin wrote:正则表达式的贪婪性造成的,呵呵。regTest=/&Content&[^&]*&\/Content&/g;因为中间部分需要不包含&号的This is Perl-like. 用 java 会类似java.util.regex.Pattern pattern = java.util.pile("&Content&[^&]*&/Content&");......而個人会用java.util.regex.Pattern pattern = java.util.pile("&Content&.*?&/Content&");
写了个javascript测试了一下,果然,呵呵&html&&script language='javascript'&var regTest=/&Content&[^&]*&\/Content&/g;var regTest2=/&Content&.*?&\/Content&/g;var strtest="&msgs&&msg&&Title&asassasa&/Title&&Content&cccccccc&/Content&&/msg&&msg&&Title&asassasa&/Title&&Content&cccccccc&/Content&&/msg&&msg&&Title&asassasa&/Title&&Content&cccccccc&/Content&&/msg&&msg&&Title&asassasa&/Title&&Content&cccccccc&/Content&&/msg&&/msgs&";alert(strtest.replace(regTest,""));alert(strtest.replace(regTest2,""));&/script&hello&/html&
& 已读帖子& 新的帖子& 被删除的帖子
Powered by & Version Jute 1.5.6 Ent
Copyright &
Cjsdn Team. All Righits Reserved.
客服电话&&&&&客服信箱&&&&&客服QQ&714923想必不少人体会过在Linux下误删文件的欲哭无泪的感觉。我整理出一份比较安全的rm脚本,贴在这里。
500多天之后,饭否回来了。这是不是以前的那个饭否不要紧,重要的是你还是那个你。(via) 有人说:“饭否回来不被阉割就很好了。”要俺看被阉割也成啊,被阉割俺也愿意继续跟它,好歹曾经完整过,不像这个新浪围脖儿,还没出生时就是太监了。(via )
总结了一款非官方的新手指南。老fanfouers请无视。
最近用上了Mac, 苦于没有一份好用的郑码输入法. 于是发挥不怕折腾的精神, 自己制作一份码表, 记在这里.
kds:“前驻法大使吴建民指出,应该理**国”,想了一下,原来两个星号是“性爱”两字,生活在一个机械屏蔽时代的中国还真有喜感。——
想必您也看到了推特上关于“”的笑话了。我正好想学一下中文分词方面的知识,这是第一篇。
一个简单的程序,统计文本文档中的单词和汉字数,逆序排列(出现频率高的排在最前面)。python实现。
简要评价一下本人读过的几本与正则表达式有关的书。个人之见,仅供参考。
网友wys提问:如何仅使用JavaScript支持的正则语法,将
&table& &p& &/p&&p& &&/p&&/table&
&table& &p& &/p&&p& &&/p&&/table&
中&table&...&/table&之间的&p&&/p&都替换为&br /&?
统计最近用过的linux命令。没什么具体用途,练习bash而已。
本文是一篇随笔,将email的anti spam技术和论坛的防灌水结合在一起讨论。从技术层面出发。不涉及其它。
按需替换,精准搜索;
有时贪婪,有时懒惰。
喜欢正则,不喜欢回溯;
喜欢用正则解决问题,也知道并非所有问题都能用正则解决。
喜欢在上讨论疑点,也喜欢在上分享心得。
自学而未成才,不是什么大牛,我是一名正则凡客。
昨天Snopo问我如何写一段正则表达式,来提取sql的条件语句。解答之余,想写一篇文章介绍一下经验。文题本来是《如何构造复杂的正则表达式》,但是觉得有些歧义,就感觉正则式本来很简单,我在教人如何将它小事化大一样。正好相反,我的本意是说,即使复杂的正则式也不怕,找出合适的方法,将其构造出来。
读者“神の呼出”询问如何格式化HTML的标签缩进,并给出了他的思路和解法,是从纯粹的正则出发。例如,寻找配对的标签要用到后向引用,标签嵌套则使用递归。不过,这两个特性虽然很有用,却不宜滥用。本文试图从另一个角度出发,简化思路,降低对正则的依赖,以便提高速度。
关于 Trie 的介绍,请读上文,此不赘述。本文主要分析 Trie 实现原理,并给出 Python 的实现。
从《》上学习到一个module:。它属于正则优化类的module,具体说来,就是提取出备选项文本的公共部分,构造“检索树”,以便最大程度上减少回溯,提升效率。
总结在 python 语言里使用正则表达式匹配中文的经验。关键词:中文,cjk,utf8,unicode,python。
49 queries in 0.415 seconds.

我要回帖

更多关于 正则表达式或者怎么写 的文章

 

随机推荐