📄 regutil.java
字号:
package com.gctech.sms.sdsms.common;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.gctech.sms.sdsms.util.CommandFilter;
/**
* <p>Title:</p>
* <p>Description:和正则表达式相关的类</p>
* <p>Copyright: GCTech (c) 2004-6-23</p>
* <p>Company: 国创科技</p>
* <p>Email: ly@gctech.com.cn</p>
*
*
* @version 1.0
* @author liyi
*/
public class RegUtil {
public static void main(String[] args) {
String[] a = getSmContent("a c c: k");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
/**
* 根据给定内容分解短信内容
*
* @param content传入字符串
* @return 字符串数组
*/
public static String[] getSmContent(String content) {
Pattern pattern = null;
Matcher matcher = null;
String[] result;
pattern = Pattern.compile(splitContent);
result = pattern.split(content, 0);
return result;
}
/**
* 使用指定正则表达式截取字符串
*
* @param content传入的字符串
* @param reg正则表达式
* @return
*/
public static String[] splitWithReg(String input, String reg) {
Pattern pattern = null;
Matcher matcher = null;
String[] result;
pattern = Pattern.compile(reg);
result = pattern.split(input, 0);
return result;
}
/**
* 查找命令是否是有效指令
*
* @param operateNo业务代码
* @param desStr指令
* @return
*/
public static boolean filterCommand(String operateNo, String desStr) {
Pattern p = null; //正则表达式
Matcher m = null; //操作的字符串
p = Pattern.compile((String)CommandFilter.commandMap.get(operateNo));
m = p.matcher(desStr);
return m.find();
}
//传入字符串分解规则
private static final String splitContent = " +|:";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -