Last active
December 24, 2015 07:49
-
-
Save edpichler/6766187 to your computer and use it in GitHub Desktop.
Regex problem.
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.ArrayList; | |
import java.util.List; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class TestRegex { | |
private static final String PTR_PERSON = "(\\d\\.)(([^\\d ])([a-z/ ]*))"; | |
private static List<String> findPersonDetails(String input) { | |
Pattern pattern = Pattern.compile(PTR_PERSON, Pattern.CASE_INSENSITIVE); | |
Matcher matcher = pattern.matcher(input); | |
List<String> personDetails = new ArrayList<String>(); | |
while (matcher.find()) { | |
personDetails.add(matcher.group(2).trim()); | |
} | |
return personDetails; | |
} | |
public static void main(String[] args) { | |
String text = " 1.AAAA/BBBB\n" + | |
" 1.2AAAA/BBBB\n" + | |
" 2 G31463 T 03OCT 4 AAABBB HK1 1810 2009"; | |
//locally it works, but on Amazon EC2 always find 0 persons. | |
List<String> det = findPersonDetails(text); | |
System.out.println("Must return '1':"); | |
System.out.println(det.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested on Amazon Ubuntu 12.04.02 x64 EC2 instance with openjdk 7.
ubuntu@ip-10-162-26-6:
$ uname -a$ java -versionLinux ip-10-162-26-6 3.2.0-40-virtual #64-Ubuntu SMP Mon Mar 25 21:42:18 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ip-10-162-26-6:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
ubuntu@ip-10-162-26-6:
$ javac -version$ javac TestRegex.javajavac 1.7.0_25
ubuntu@ip-10-162-26-6:
ubuntu@ip-10-162-26-6:
$ java TestRegex$Must return '1':
1
ubuntu@ip-10-162-26-6: