Last active
August 29, 2015 14:13
-
-
Save sharno/c70cbf06377b36168e7f to your computer and use it in GitHub Desktop.
small currency detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Main { | |
public static void main(String[] args) { | |
String message= "From HSBC: 08JAN15 METRO MARKET EGP 48.70-"; | |
Matcher currencyMatcher = Pattern.compile("(?:EGP|USD|EUR)(?=\\s\\d*)").matcher(message); | |
Matcher amountMatcher = Pattern.compile("\\d*,?\\d*,?\\d+\\.\\d+").matcher(message); | |
Matcher signMatcher = Pattern.compile("[+-]$").matcher(message); | |
Matcher dateMatcher = Pattern.compile("\\d{2}(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\\d{2}").matcher(message); | |
if (currencyMatcher.find()) { | |
System.out.println(currencyMatcher.group()); | |
} | |
if (amountMatcher.find()) { | |
System.out.println(amountMatcher.group()); | |
} | |
if (signMatcher.find()) { | |
System.out.println(signMatcher.group()); | |
} | |
if (dateMatcher.find()) { | |
System.out.println(dateMatcher.group()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment