java 的正则表达式(Parrent),匹配字符串
2007-11-22 15:48
381 查看
import java.util.regex.*;
public class UsePattern {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="we call this the live-code appproach."
+"these examples are avaible from three location-they are "
+"on the CD that accompabies this book";
Pattern expression=Pattern.compile("[a-zA-Z]+");
Matcher matcher=expression.matcher(str);
String word=null;
int n=0;
while(matcher.find())
{
word=matcher.group();
System.out.print(word+"/t");
if((n+1)%4==0)
System.out.println();
n++;
}
System.out.print("/n单词的总数:"+n);
System.out.println("/n有9个字母(含9个)以上的单词有:");
Pattern expression1=Pattern.compile("[a-zA-Z]{9,}");
Matcher matcher1=expression1.matcher(str);
while(matcher1.find())
{
word=matcher1.group();
System.out.print(word+"/n");
}
System.out.println();
}
}
public class UsePattern {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="we call this the live-code appproach."
+"these examples are avaible from three location-they are "
+"on the CD that accompabies this book";
Pattern expression=Pattern.compile("[a-zA-Z]+");
Matcher matcher=expression.matcher(str);
String word=null;
int n=0;
while(matcher.find())
{
word=matcher.group();
System.out.print(word+"/t");
if((n+1)%4==0)
System.out.println();
n++;
}
System.out.print("/n单词的总数:"+n);
System.out.println("/n有9个字母(含9个)以上的单词有:");
Pattern expression1=Pattern.compile("[a-zA-Z]{9,}");
Matcher matcher1=expression1.matcher(str);
while(matcher1.find())
{
word=matcher1.group();
System.out.print(word+"/n");
}
System.out.println();
}
}
相关文章推荐
- java 通过正则表达式获取匹配字符串的例子
- Java正则表达式,匹配、替换字符串中的占位符
- 关于利用正则表达式捕获匹配的字符串的简单功能(java)
- java 正则匹配空格字符串 正则表达式截取字符串
- java正则表达式匹配字符串字母,数字,空格和其他字符出现次数
- 【java基础之代码】【正则表达式匹配字符串检测输入的是否为手机号码】
- JAVA 正则表达式:使用group方法计算匹配到的字符串个数
- java正则表达式,读取字符串不区分大小写;正则匹配表达式中的数字或者字母;正则匹配网页中的邮箱
- java中的正则表达式 字符串的拆分,匹配,替换
- Java正则表达式匹配一个时间格式的字符串
- java 使用正则表达式获取匹配的字符串
- 【Java】正则表达式匹配多单词任意顺序组合的字符串
- 正则表达式获取匹配字符串
- 获取正则表达式匹配的字符串
- 用java正则表达式验证字符串(邮箱与网址)
- 匹配2-5个中文字符串正则表达式.
- 正则表达式匹配字符串
- java正则表达式 匹配文本中的网址
- java 正则表达式高级篇(四种常用的处理方式:匹配 分割 替代 获取)
- JAVA正则表达式匹配,替换,查找,切割的总结