Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Mateusz Pawelec I4B3S1//
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.UnsupportedEncodingException;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class regexZad3 {
- // wp.pl
- static String FILENAME = "wp.htm";
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- String message = "";
- List<String> resultList = new LinkedList<String>();
- BufferedReader in = null;
- try {
- in = new BufferedReader(new InputStreamReader(new FileInputStream(FILENAME), "UTF-8"));
- } catch (UnsupportedEncodingException | FileNotFoundException e1) {
- e1.printStackTrace();
- }
- System.out.println("Podaj ciag znakow ktore chcesz znalezc");
- String input = keyboard.next();
- String fileLine;
- String pattern1 = ">(.*?"+input+".*?)<";
- Pattern p1 = Pattern.compile(pattern1, Pattern.CASE_INSENSITIVE);
- try {
- while ((fileLine = in.readLine()) != null) {
- fileLine = fileLine + "<";
- Matcher m1 = p1.matcher(fileLine);
- if(m1.find()){
- String tmp = m1.group(1);
- int index = tmp.lastIndexOf(">");
- tmp = tmp.substring(index + 1);
- tmp = tmp.trim();
- if(tmp.indexOf("/") == -1)resultList.add(tmp);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- for(String str : resultList) {
- message += str;
- message += "\n";
- }
- System.out.println(message);
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement