http://docs.oracle.com/javase/tutorial/essential/regex/test_harness.html
这里的问题就是Eclipse不支持Console.
也就是
Console console = System.console();
System.out.println(console);
这里的结果为null.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=122429
http://stackoverflow.com/questions/104254/java-io-console-support-in-eclipse-ide#105403
在Eclpise中无法获取Console对象。
所以只能在CMD中使用。
在Eclipse里面只能这样用
package com.lj.duitang;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTestHarness
{
private static String readLine(String prompt) {
String line = null;
Console c = System.console();
if (c != null) {
line = c.readLine(prompt);
} else {
System.out.print(prompt);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
line = bufferedReader.readLine();
} catch (IOException e) {
//Ignore
}
}
System.out.println("line= "+line.length());
return line;
}
public static void main(String[] args)
{
Console console = System.console();
System.out.println(console);
// if(console == null){
// System.err.println("No console.");
// System.exit(1);
// }
while(true){
Pattern pattern =Pattern.compile(readLine("%nEnter your regex: "));
Matcher matcher = pattern.matcher(readLine("Enter input string to search:"));
boolean found=false;
while(matcher.find()){
// console.format("I found the text"+
// "\"%s\" starting at "+
// "index %d and ending at index %d.%n",
// matcher.group(),matcher.start(),matcher.end()
// );
System.out.println("I found the text \""+matcher.group()+"\" starting at index "+matcher.group()+"starting at "+matcher.start()+
" and ending at index "+matcher.end());
found=true;
}
if(!found){
//console.format("No match found.%n");
System.out.println("No match found.%n");
}
}
}
}
分享到:
相关推荐
The Test Harness is a powerful application for testing devices which use DNP3, IEC 60870-5, or Modbus.
plivo-java.zip,用于plivo服务的java助手库plivo java助手库
social.zip,Crafter社交网站
离线安装包,亲测可用
Fault-Injection-Test-Harness
离线安装包,亲测可用
Stubby C是C Test Harness生成器,可帮助开发人员创建有效的C单元测试。 Stubby C可以与其他单元测试解决方案(例如check或CUnit)结合使用。
一个简单的测试工具框架,提供了不错的GUI和简单的控制机制。 测试用例必须用Java编写,但是该工具可以用于测试几乎所有东西。
离线安装包,亲测可用
Stubby C ++是促进C ++单元测试的C ++测试工具生成器。
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
[citest commit:<sha1>] -如果提交者不受信任,将要测试的提交列入白名单 也可以使用needs-ci标签将PR中的所有提交列入白名单。 但是,这仅应与受信任的提交者一起使用,因为他们仍然可以在PR中更改提交。 部署工作...
HL7 Test Harness系统是HL7 v3消息一致性测试应用程序,还提供了模拟客户端和/或服务器系统的消息处理动作的功能。 该应用程序提供消息工作流程,格式和内容测试。
RA TestHarness 将通过解析嵌入在由 Servlet 或 CGI 机制生成的 HTML 中的隐藏测试信息来自动测试网页交互。 RATH 可以与 ANT 和 JUNIT 一起使用,作为开发、测试和部署策略的一部分。
git clone https://github.com/tc39/test262.git --depth 1 cd test262 对于测试创作和测试执行: 对于测试创作和执行: npm install -g test262-harness 运行test262-harness --help以获得各种配置选项的详细...
notifo-log4j-appender.zip,通过notifo服务发送消息的notifo log4j appender log4j appender
盐配方测试线束 在干净,隔离的环境中运行所需的许多pytest套件。 假设: make在您的系统上并且可用。 如果不是,或者您不确定make是什么,那么...cp -r tmp/formula-test-harness/tools tools cp -r tmp/formula-test
auth0-rules-local-testharness库提供了一种使用本地沙箱环境来部署,执行和测试Auth0 Rules输出的Auth0 Rules方法。 它非常易于使用,并且需要不到5分钟的时间才能开始测试您的Auth0规则! 您应该编写Auth0 Rules...
cko-test-harness是Checkout.com统一API的网络实现。 它使用户可以快速测试并了解有效负载级别的事务请求和响应详细信息。 实时Web应用程序可从获得。 支持的API和服务 客户API 活动API 镜框 托管付款页面 付款...
jar包,官方版本,自测可用