请教一个正则表达式,替换所有除了字母和单个空格外的所有字符例如:Contents
PrefaceChapter 1: Getting started with the ASP.NET MVC Framework这段要替换为Contents Preface Chapter Getting started with the ASP NET MVC Framework求解
PrefaceChapter 1: Getting started with the ASP.NET MVC Framework这段要替换为Contents Preface Chapter Getting started with the ASP NET MVC Framework求解
解决方案 »
- Scanner小问题
- 请问java中System.out.println()中打印出来的是换行,还是回车+换行。
- 什么时候length什么时候size
- 求助:怎么把list里面的东西串成一个字符串!!
- 请问::下面代码那有错误?怎么改?谢谢!
- 敢问大侠用java编写好桌面应用程序后该如何在其他机器上运行?
- 怎样把一个字节数组中的一部分复制到另一个数组中?
- 初学JAVA,请大侠们指教
- 请高手指路:如何在WIN98下,设置JDK开发环境???谢谢!
- 关于awt包中的Canvas类?
- 新手求教啊。import com.borland.jbcl.layout.*;这个东西老是出错啊
- 怎样让Canvas里面的字符串移动
package com.pattern.test;import java.util.regex.Pattern;public class PatternTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Pattern pa=Pattern.compile("[\\W,\\d]+");
String str="Chapter 1: Getting started with the ASP.NET MVC Framework";
String[] s=pa.split(str);
for(String st:s){
System.out.println(st);
}
}}
package jeelon.regularExpression.Test;public class Base { public static void main(String[] args) {
String yuanlaiString = "Contents " + "\n" +
"Preface " +"\n" +
"Chapter 1: Getting started with the ASP.NET MVC Framework" ;
System.out.println("原来的:");
System.out.println(yuanlaiString);
System.out.println("替换过后的:");
System.out.print(yuanlaiString.replaceAll("[^a-zA-Z,\\r]", " "));
}
}原来的:
Contents
Preface
Chapter 1: Getting started with the ASP.NET MVC Framework
替换过后的:
Contents Preface Chapter Getting started with the ASP NET MVC Framework
MEAP Edition
Manning Early Access Program
Copyright 2007 Manning PublicationsFor more information on this and other Manning titles go to
www.manning.com
Contents
Preface
就没办法了
System.out.print(yuanlaiString.replaceAll("[^a-zA-Z,\\r+]", " "));具体问题 具体分析 呵呵 ...
str = str.replaceAll("(?s)[^a-zA-Z]+"," ");