Lpc*_*ark 1 java regex matcher replaceall
对不起,我不得不重新写这个问题,我正在完成它,有人关闭它.他们不善解释为什么我不得不重新发布?请告诉我什么是令人困惑的.
要点:我想用匹配的部分替换正则表达式匹配,所以如果我正则表达式我希望它替换为{hi}如果正则表达式匹配我想要替换为{at}
这真是太棒了看看这两个字母的单词得到了更换后的回报
this <h1>is</h1> awesome look <h1>at</h1> this two letter words get replaced
Run Code Online (Sandbox Code Playgroud)
注意是什么和匹配正则表达式\ b\w\w\b将匹配替换
这是我正在研究的代码...不要判断它没有完成,但我只是有点困惑,并想知道是否有一个更简单的方法.我正在搜索字符串并找到匹配项,然后我将把它转到一个arraylist并替换每一个.问题是我要替换的问题之一是{并且我想用{{}替换它现在看起来这将不断替换括号,因为我继续添加它们...所以我的另一个想法是将它们全部替换掉逐个char by char并添加到一个新StringBuilder对象?
ArrayList<String> replacements= new ArrayList<String>();
String s="::";
s+=command;
Pattern p= Pattern.compile("[!-~]");
Matcher match= p.matcher(this.execution);
while(match.find()){
replacements.add(match.group());
}
StringBuilder string= new StringBuilder();
for(int i=0;i<this.execution.length();i++){
String a=new String(execution.charAt(i));
if(...){
...
}
}
s+="::"+this.execution;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
182 次 |
| 最近记录: |