81,092
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String args[]) {
String[] array = { "<[\nddddddddddddddddddddddddddddddd\n]>",
"<[\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n]>" };
String regex = "\\<\\[([^\\[\\]]*)\\]\\>";
Pattern p = Pattern.compile(regex, Pattern.DOTALL);
Matcher m = null;
for (String str : array) {
m=p.matcher(str);
while (m.find()) {
System.out.println("match=" + m.group(1));
}
}
}
}
import java.util.regex.*;
import java.io.*;
public class Test2
{
public static void main(String[] args)
{
BufferedReader br = null;
boolean start = false;
try{
br = new BufferedReader(new FileReader("in.txt"));
String s = "";
while((s = br.readLine().trim())!=null){
if(s.equals("<[")){//s.startsWith("<[")&&s.endsWith("]>")
start = true;
}else if(s.equals("]>")){
start = false;
}else if(start){
System.out.println(s);
}
}
br.close();
}catch(Exception e){/*...*/}
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class w {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File f = new File("h:\\M.txt");
StringBuffer sb = new StringBuffer();
BufferedReader br = null;
String s;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while((s = br.readLine())!=null)
{
sb.append(s);
}
Pattern p = Pattern.compile("<\\[(.*?)\\]>");
Matcher m = p.matcher(sb.toString());
while(m.find())
{
System.out.println(m.group(1));
}
}
}
import java.util.regex.*;
public class CsdnHmilyl
{
public static void main(String[] args)
{
String s = "123abc<[ddddddddddddddddddddddddddddddd]>abc123";
Pattern p = Pattern.compile("<.(\\w+).>");
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
}
}