简体   繁体   English

String.replaceAll在Eclipse之外无法正常工作吗?

[英]String.replaceAll not working outside of Eclipse?

I have the following line of code: 我有以下代码行:

//line is of the format: "Garbage text (desired text)"
String target = line.replaceAll("Garbage text \\((.+)\\)", "$1");
return target; //separated for clarity

Output from within Eclipse Kepler using jre1.6 , the above returns to me the desired text. 使用jre1.6Eclipse Kepler内部输出,以上返回给我所需的文本。 However, when I compile my code into a runnable jar, the above returns the entire string, as if the replaceAll was never executed. 但是,当我将代码编译到可运行的jar中时,上面的代码将返回整个字符串,就好像从未执行过replaceAll

When I try 当我尝试

line.replaceAll(".+\\((.+)\\)", "$1")

I get the same results. 我得到相同的结果。

I tried changing my build path to use jre1.7 , as well, but to no avail. 我也尝试将构建路径更改为使用jre1.7 ,但无济于事。

My environment: 我的环境:

Windows 7 x64 Professional
Java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

Can anyone tell me what's going on? 谁能告诉我怎么回事?

Figured it out. 弄清楚了。 It had nothing to do with Eclipse or Java, but all to do with the input file. 它与Eclipse或Java无关,而与输入文件有关。 The jar was running from a different location with a file that had the same name. 该jar从一个具有相同名称的文件的不同位置运行。 The two files had slightly different formats, and that is what threw me off. 这两个文件的格式略有不同,这就是让我失望的地方。

Thanks for all the help, sorry this was a waste of time. 感谢您的所有帮助,对不起,这是浪费时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM