Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;
- import java.io.IOException;
- import java.sql.Struct;
- import java.util.regex.*;
- import java.util.Scanner;
- import java.io.FileInputStream;
- public class RegExp {
- //static Scanner in;
- public static void main(String args[]) {
- String str;
- Pattern myRegex;
- myRegex = Pattern.compile
- ("(?i)([а-я]{1,}) ([а-я]{1,}) ([а-я]{1,}) ([0-9]{5,11}) " +
- "([0-9a-z.,-?!]{1,}) ([0-9]{2}.[0-9]{2}.[0-9]{4})", Pattern.UNICODE_CHARACTER_CLASS) ;
- Matcher regexMatch;
- try (FileInputStream fin = new FileInputStream("file.txt")) {
- Scanner sf = new Scanner(fin);
- while (sf.hasNext()) {
- str = sf.nextLine();
- regexMatch = myRegex.matcher(str);
- if (regexMatch.find()) System.out.println(
- "\nФамилия: " + regexMatch.group(1) +
- "\nИмя: " + regexMatch.group(2) +
- "\nОтчество: " + regexMatch.group(3) +
- "\nТелефон: " + regexMatch.group(4) +
- "\nНик: " + regexMatch.group(5) +
- "\nДата рождения: " + regexMatch.group(6));
- else System.out.println("!!!Wrong string: " + str);
- }
- sf.close(); fin.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment