Java 正则表达式
来源:互联网 发布:网络造谣怎样算违法 编辑:程序博客网 时间:2024/06/05 12:06
正则表达式
常用正则表达式:
“^\d+$” //非负整数(正整数 + 0)
“^[0-9][1-9][0-9]$” //正整数
“^((-\d+)|(0+))$” //非正整数(负整数 + 0)
“^-[0-9][1-9][0-9]$” //负整数
“^-?\d+$” //整数
“^\d+(.\d+)?$” //非负浮点数(正浮点数 + 0)
“^(([0-9]+.[0-9][1-9][0-9])|([0-9][1-9][0-9].[0-9]+)|([0-9][1-9][0-9]))$” //正浮点数
“^((-\d+(.\d+)?)|(0+(.0+)?))$” //非正浮点数(负浮点数 + 0)
“^(-(([0-9]+.[0-9][1-9][0-9])|([0-9][1-9][0-9].[0-9]+)|([0-9][1-9][0-9])))$” //负浮点数
“^(-?\d+)(.\d+)?$” //浮点数
“^[A-Za-z]+$” //由26个英文字母组成的字符串
“^[A-Z]+$” //由26个英文字母的大写组成的字符串
“^[a-z]+$” //由26个英文字母的小写组成的字符串
“^[A-Za-z0-9]+$” //由数字和26个英文字母组成的字符串
“^\w+$” //由数字、26个英文字母或者下划线组成的字符串
“^[\w-]+(.[\w-]+)*@[\w-]+(.[\w-]+)+$” //email地址
“^[a-zA-z]+://(\w+(-\w+))(.(\w+(-\w+)))(\?\S)?$” //url
最简单的用法:
Pattern pattern =Pattern.complile(patternString);Matcher matcher = pattern.matcher(input);while (matcher.find()){ int start = matcher.start(); int end = matcher.end(); String match = input.substring(start,end);}
package com.xb.Regex;import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * * @author wyb * */public class RegexTest { public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.println("Enter pattern:"); String patternString= in.nextLine(); Pattern pattern = Pattern.compile(patternString); while(true){ System.out.println("Enter string to match:"); String input = in.nextLine(); if (input == null || input.equals("")) { return; } Matcher matcher=pattern.matcher(input); while(matcher.find()){ int start = matcher.start(); int end = matcher.end(); String match = input.substring(start,end); System.out.println(match); } } }}
0 0
- Java 正则表达式正则
- 【正则表达式】Java正则表达式
- 正则表达式 JAVA正则表达式
- 【Java】【正则表达式】正则表达式
- Java 正则表达式详解_正则表达式
- java正则表达式!正则表达式踩坑!!!
- 正则表达式工具类,正则表达式封装,Java正则表达式
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- java和正则表达式
- java正则表达式详解!
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- tomcat 启动不了的原因
- 将PDF文件转换成可编辑的word方法
- iOS开发参考
- #笔记#圣思园 JavaSE 第61讲——Java反射机制
- 啊啊啊
- Java 正则表达式
- unidac这家公司还做了一个sdac, 据说支持Table-valued parameter, 但unidac又不支持
- ERROR: 98: Error '!obj' trying to fetch default input device's sample rate
- Nehe第六章纹理映射
- JS运动之多物体框架--多个div变宽
- 对象string互转
- junit1
- prototype
- popwind 如何使背景变暗