㈠ java模糊匹配 字元串匹配某個字元串
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
publicclassTest2{
publicstaticvoidmain(String[]args){
Test2test=newTest2();
Stringtext="測試123abc實名失敗測試123abc";
System.out.println(test.match(text));
}
privatebooleanmatch(Stringtext){
Patternpattern=Pattern.compile("(44|實名失敗|實名不成功|認證失敗|實名認證失敗)");
Matchermatcher=pattern.matcher(text);
if(matcher.find()){
System.out.println("匹配到了:"+matcher.group(1));
returntrue;
}
System.out.println("沒有匹配到");
returnfalse;
}
}
㈡ 如何用java實現模糊查詢
你調用這個方法,返回的List就是你要的結果了
public static List<Integer> find(List<String> strList) {
List<Integer> resultList = new ArrayList<Integer>();
String regex = "[a-zA-Z]{3}02[a-zA-Z]{2}02";
for(int i = 0; i < strList.size(); i++) {
Matcher matcher = Pattern.compile(regex).matcher(strList.get(i));
if(matcher.matches()) {
resultList.add(i);
}
}
return resultList;
}
㈢ java語言實現滿足多條件匹配簡單過濾輸出問題
package;
importjava.io.File;
importjava.io.FileWriter;
importjava.io.IOException;
importjava.util.Arrays;
importjava.util.LinkedList;
publicclassCombin
{
privatestaticStringline=System.getProperty("line.separator");
privatestaticLinkedList<String[]>recursionSub(LinkedList<String[]>list,intcount,String[]array,intind,
intstart,int...indexs)
{
start++;
if(start>count-1)
{
returnnull;
}
if(start==0)
{
indexs=newint[array.length];
}
for(indexs[start]=ind;indexs[start]<array.length;indexs[start]++)
{
recursionSub(list,count,array,indexs[start]+1,start,indexs);
if(start==count-1)
{
String[]temp=newString[count];
for(inti=count-1;i>=0;i--)
{
temp[start-i]=array[indexs[start-i]];
}
booleanflag=true;
L:for(inti=0;i<temp.length;i++)
{
for(intj=i+1;j<temp.length;j++)
{
if(temp[i]==temp[j])
{
flag=false;
breakL;
}
}
}
if(flag)
{
list.add(temp);
}
}
}
returnlist;
}
privatestaticvoidfilter(LinkedList<String[]>list)throwsIOException
{
Filefile=newFile("c:/116.txt");
FileWriterfw=newFileWriter(file);
for(String[]strings:list)
{
intcount1=0,count2=0,count3=0;
Stringtemp=Arrays.toString(strings).replaceAll("[\[\]\s]","");
if(temp.contains("01"))
{
count1++;
count3++;
}
if(temp.contains("02"))
{
count1++;
count2++;
}
if(temp.contains("03"))
{
count1++;
}
if(temp.contains("06"))
{
count2++;
count3++;
}
if(temp.contains("08"))
{
count2++;
count3++;
}
if(temp.contains("09"))
{
count2++;
count3++;
}
if(temp.contains("07"))
{
count3++;
}
if(temp.contains("10"))
{
count3++;
}
if(temp.contains("11"))
{
count3++;
}
if(count1>=1&&count1<=2&&count2>=1&&count2<=3&&count3>=0&&count3<=2)
{
fw.write(temp+line);
}
}
fw.flush();
fw.close();
}
publicstaticvoidmain(String[]args)throwsIOException
{
String[]A={"01","02","03","04","05","06","07","08","09","10","11"};
LinkedList<String[]>list=newLinkedList<String[]>();
recursionSub(list,6,A,0,-1);
//假定從1-11這11個數字中任選6個全組合輸出(每行輸出6個不相同數字,並且從小到大排列)
for(String[]strings:list)
{
Stringtemp=Arrays.toString(strings).replaceAll("[\[\]\s]","");
System.out.println(temp);
}
//將第一問得到數據過濾,並且同時滿足下面3條條件就輸出,輸出結果用"116.txt"保存在C盤
filter(list);
}
}
㈣ java模糊匹配
雙向字元求和,簡單的模糊匹配
㈤ 如何在JAVA里做 模糊查詢
可以使用正則表達式實現, 可以字元串本身的方法實現,請看示例:
importjava.util.regex.Pattern;
/**
*@authorArvin
*@time2016/11/821:38
*/
publicclassMain{
publicstaticvoidmain(String[]args){
Stringkeyword=".(你好)";
StringcontentOne="hello.(你好)asd";//LIKE匹配
StringcontentTwo="你好";//LIKE不匹配
//方法一:利用正則表達式
//構造正則表達式
Patternregex=Pattern.compile(keyword);
System.out.println(regex.matcher(contentOne).find());//true
System.out.println(regex.matcher(contentTwo).find());//false
//方法二:利用String的contain方法
System.out.println(contentOne.contains(keyword));//true
System.out.println(contentTwo.contains(keyword));//false
//方法三:利用indexOf方法,找得到說明包含
System.out.println(contentOne.indexOf(keyword)>-1);//true
System.out.println(contentTwo.indexOf(keyword)>-1);//false
}
}
㈥ java中如何模糊查找
你好,按照你的要求代碼如下
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class text {
public static void main(String[] args) {
try {
String key = "這個字元串是將進行模糊查找的";
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\一篇文章.txt")));
StringBuffer str = new StringBuffer();
String temp;
while (null != (temp = in.readLine())) {
str.append(temp);
}
int first = str.indexOf(key);
if (first != -1) {
System.out.println("【" + key + "】在文章中的首次出現位置是:" + first);
} else {
System.out.println("【" + key + "】在文章中沒有找到");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
㈦ java 用字元串模糊匹配另一個字元串
按LS所說的確可以。要是一定要用String的話可以用
String[] s;
for(String ss:s)
if(ss.contains("貿易"))
System.out.println(ss);
這樣回的答方法。
㈧ java語言如何實現同時多條件匹配過濾編程問題
不能理解你的條件2
什麼意思?
每行輸出6個不相同數字既然是不同的數字,你下面的含有 1個以上是不是都不成立
㈨ java中是如何實現基於文字標題的模糊匹配的,下面的代碼是實現這個功能的嗎
通過正則表達式使用正則匹配可以用於實現基於文字標題的模糊匹配。
正則表達式,又稱正專規表示法屬、常規表示法(英語:Regular Expression,在代碼中常簡寫為regex、regexp或RE),計算機科學的一個概念。正則表達式使用單個字元串來描述、匹配一系列符合某個句法規則的字元串。在很多文本編輯器里,正則表達式通常被用來檢索、替換那些符合某個模式的文本。
關於正則表達式,下面這個博客有詳細的介紹:http://blog.sina.com.cn/s/blog_9cda2bc70102w02a.html
㈩ java 中模糊查詢
select * from a where name like '%我%'
這樣查詢a表中有我字內的
select * from a where name like '我%'
這樣查詢a表中我字開頭的
select * from a where name like '%我'
這樣查詢a表中我字結尾的容