Skip to content

Instantly share code, notes, and snippets.

@edpichler
Last active December 24, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edpichler/6766187 to your computer and use it in GitHub Desktop.
Save edpichler/6766187 to your computer and use it in GitHub Desktop.
Regex problem.
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());
}
}
@phstudy
Copy link

phstudy commented Oct 1, 2013

tested on Amazon Elastic Beanstalk tomcat7 x64 EC2 instance.

[ec2-user@ip-10-121-5-162 ~]$ javac -version
javac 1.6.0_24
[ec2-user@ip-10-121-5-162 ~]$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.9) (amazon-57.1.11.9.52.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
[ec2-user@ip-10-121-5-162 ~]$ javac TestRegex.java
[ec2-user@ip-10-121-5-162 ~]$ java TestRegex
Must return '1':
1

@phstudy
Copy link

phstudy commented Oct 1, 2013

tested on Amazon Ubuntu 12.04.02 x64 EC2 instance.

ubuntu@ip-10-162-26-6:$ uname -a
Linux 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
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
ubuntu@ip-10-162-26-6:$ javac -version
javac 1.6.0_27
ubuntu@ip-10-162-26-6:
$ javac TestRegex.java
ubuntu@ip-10-162-26-6:$ java TestRegex
Must return '1':
1
ubuntu@ip-10-162-26-6:
$

@phstudy
Copy link

phstudy commented Oct 1, 2013

tested on Amazon Ubuntu 12.04.02 x64 EC2 instance with openjdk 7.

ubuntu@ip-10-162-26-6:$ uname -a
Linux 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
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 1.7.0_25
ubuntu@ip-10-162-26-6:
$ javac TestRegex.java
ubuntu@ip-10-162-26-6:$ java TestRegex
Must return '1':
1
ubuntu@ip-10-162-26-6:
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment