可能重复:
Java Regex替换为捕获组
有没有办法用修改后的捕获组内容替换正则表达式?
例:
Pattern regex = Pattern.compile("(\\d{1,2})");
Matcher regexMatcher = regex.matcher(text);
resultString = regexMatcher.replaceAll("$1"); // *3 ??
Run Code Online (Sandbox Code Playgroud)
而且我想用$ 1替换所有出现次数乘以3.
编辑:
看起来,有些不对劲:(
如果我使用
Pattern regex = Pattern.compile("(\\d{1,2})");
Matcher regexMatcher = regex.matcher("12 54 1 65");
try {
String resultString = regexMatcher.replaceAll(regexMatcher.group(1));
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它抛出IllegalStateException:找不到匹配项
但
Pattern regex = Pattern.compile("(\\d{1,2})");
Matcher regexMatcher = regex.matcher("12 54 1 65");
try {
String resultString = regexMatcher.replaceAll("$1");
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
工作正常,但我不能改变$ 1 :(
EDIT2:
现在,它的工作:)
你能告诉我在Windows XP系统上默认安装的.NET框架吗?
因为我想编写一个不需要安装任何其他东西的C#应用程序.
如果没有办法不强迫用户下载.net框架(例如3.5)但是安装它?
如何设置SWT Browser发送的用户代理头?
编辑:或者是否有任何java的浏览器库允许指定用户代理?
我有以下代码:
Object obj = 3;
//obj.equals(3); // so is this true?
Run Code Online (Sandbox Code Playgroud)
是否obj等于3?
当这个监听器在事件发生后添加时,会JQuery运行传入的函数吗?$(window).load(callback)window.load
using System;
using System.Collections.Generic;
public class Test
{
static List<T> F<T>(IDictionary<int, IEnumerable<T>> dictionary)
{
// ...
return new List<T>();
// ...
}
public static void Main()
{
var mydict = new Dictionary<int, LinkedList<int>>();
F(mydict);
}
}
Run Code Online (Sandbox Code Playgroud)
运行代码后的错误消息:
prog.cs(16,3): error CS0411: The type arguments for method `Test.F<T>(System.Collections.Generic.IDictionary<int,System.Collections.Generic.IEnumerable<T>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
Compilation failed: 1 error(s), 0 warnings
Run Code Online (Sandbox Code Playgroud) Vector原始的克隆/副本中的元素是?
SomeType myVar = new SomeType();
myVar.something = "AStringValue";
myVar.i = 123;
Vector<SomeType> v1 = new Vector<SomeType>();
v1.add(myVar);
Vector<SomeType> v2 = new Vector<SomeType>();
v2.add(myVar);
v1.get(0).i = 321;
Run Code Online (Sandbox Code Playgroud)
在这段代码之后这些陈述是真的v2.get(0).i == 321,myVar.i == 321?
java ×4
.net ×1
c ×1
c# ×1
generics ×1
http-headers ×1
javascript ×1
jquery ×1
object ×1
pointers ×1
regex ×1
swt ×1
user-agent ×1
vector ×1
windows-xp ×1