高人帮我写个正则表达式(java的)

find_1 2010-04-10 02:16:22
从一字符串里找出符合条件的字符串.
字符串规则: $ + 一个单词 + { + 一系列字符 + }
比于:$word{abc=s123|cde=find|efg=www}
...全文
81 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
find_1 2010-04-11
  • 打赏
  • 举报
回复
谢谢
anidy041407028 2010-04-10
  • 打赏
  • 举报
回复

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Test {

public static void main(String[] args) {
String testStr = "good$String{find|and$%h=+}substr**yes+_$String2${find2|***&%^hefdsa@h";
findPatternStr(testStr);

}

/*
* @func: 查找符合要求的字符串
* 规则: $ + 一个单词 + { + 一系列字符 + }如:$word{abc=s123|cde=find|efg=www}
* @param: str 进行匹配的测试字符串
*
*/

public static void findPatternStr(String str) {

String regStr = "\\$[a-zA-Z]+\\{.+\\}";
Pattern p = Pattern.compile(regStr);
Matcher m = p.matcher(str);
while(m.find()){
System.out.println("find the string:["+m.group()+"]");
}
}

}
find_1 2010-04-10
  • 打赏
  • 举报
回复
测试通不过
wind1373290 2010-04-10
  • 打赏
  • 举报
回复
^\$[a-zA-Z]+\{\\w\}$

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧