MierivaL

Регуляр очка

Apr 5th, 2019
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;
  2.  
  3. import java.io.IOException;
  4. import java.sql.Struct;
  5. import java.util.regex.*;
  6. import java.util.Scanner;
  7. import java.io.FileInputStream;
  8.  
  9. public class RegExp {
  10.     //static Scanner in;
  11.  
  12.     public static void main(String args[]) {
  13.         String str;
  14.         Pattern myRegex;
  15.         myRegex = Pattern.compile
  16.                 ("(?i)([а-я]{1,}) ([а-я]{1,}) ([а-я]{1,}) ([0-9]{5,11}) " +
  17.                         "([0-9a-z.,-?!]{1,}) ([0-9]{2}.[0-9]{2}.[0-9]{4})", Pattern.UNICODE_CHARACTER_CLASS) ;
  18.         Matcher regexMatch;
  19.  
  20.         try (FileInputStream fin = new FileInputStream("file.txt")) {
  21.             Scanner sf = new Scanner(fin);
  22.             while (sf.hasNext()) {
  23.                 str = sf.nextLine();
  24.                 regexMatch = myRegex.matcher(str);
  25.  
  26.                 if (regexMatch.find()) System.out.println(
  27.                         "\nФамилия: " + regexMatch.group(1) +
  28.                         "\nИмя: " + regexMatch.group(2) +
  29.                         "\nОтчество: " + regexMatch.group(3) +
  30.                         "\nТелефон: " + regexMatch.group(4) +
  31.                         "\nНик: " + regexMatch.group(5) +
  32.                         "\nДата рождения: " + regexMatch.group(6));
  33.                 else System.out.println("!!!Wrong string: " + str);
  34.             }
  35.             sf.close(); fin.close();
  36.         } catch (IOException e) {
  37.             e.printStackTrace();
  38.         }
  39.     }
  40. }
Add Comment
Please, Sign In to add comment