That fuck shit the fascists are using
at master 44 lines 1.4 kB view raw
1/** 2 * Copyright (C) 2011 Whisper Systems 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17package org.tm.archive.service; 18 19 20 21 22import java.util.Optional; 23import java.util.regex.Matcher; 24import java.util.regex.Pattern; 25 26public class VerificationCodeParser { 27 28 private static final Pattern CHALLENGE_PATTERN = Pattern.compile("(.*\\D|^)([0-9]{3,4})-?([0-9]{3,4}).*", Pattern.DOTALL); 29 30 public static Optional<String> parse(String messageBody) { 31 if (messageBody == null) { 32 return Optional.empty(); 33 } 34 35 Matcher challengeMatcher = CHALLENGE_PATTERN.matcher(messageBody); 36 37 if (!challengeMatcher.matches()) { 38 return Optional.empty(); 39 } 40 41 return Optional.of(challengeMatcher.group(challengeMatcher.groupCount() - 1) + 42 challengeMatcher.group(challengeMatcher.groupCount())); 43 } 44}