0

This is my first post. I want to extract some special pattern from a String. I searched and found this answer Using Java to find substring of a bigger string using Regular Expression

This was exactly what i needed. Unfortunatly it does not work

My Code looks like this:

String next = ">GID1_seq1 ABW28161.1 lipid-A-disaccharide synthase, putative [Acaryochloris marina MBIC11017]";
        Pattern p = Pattern.compile("(?i).*");
        Matcher m = p.matcher(next);
        if(m.matches()){
            Pattern p1 =  Pattern.compile("GID\\d*_seq\\d*");
            Matcher m1 = p1.matcher(next);
            if(m1.matches()) {
                System.out.println(m1.group(2));
            }
            else{
                System.out.println("not a match");
            }




        }

But it does not work i also tried to just match on "GID1_seq1" but also this does not work where is my problem ?

Edit: forget about the m1.group(2) i get "not a match" everytime

zeronyk
  • 11
  • 2
  • `matches("GID\\d*_seq\\d*")` will try to match the whole string, it fails right there. The question about why `.group(2)` is empty - there are no capturing groups in your pattern. Just add two pairs of unescaped `(...)` in the pattern, and it will be populated if you use `.find()` and there is a match. – Wiktor Stribiżew Jun 12 '17 at 12:47
  • ok thanks but how do i get the subseqence extracted like i want the output "GID1_seq1" as substring is there no way to get it ? – zeronyk Jun 12 '17 at 12:48
  • https://ideone.com/nyvNgc – Wiktor Stribiżew Aug 31 '17 at 08:30

0 Answers0