Matcher and regex

I have this string newstr that I want to parse:

[( ?A = <http://www.semanticweb.org/vassilis/ontologies/2013/5/Test#Hello> ), ( ?A = <http://www.semanticweb.org/vassilis/ontologies/2013/5/Test#World> )]

With the code shown below I get this as result:

[#Hello>, #World>]

What should I change to get:

Hello, World

Code:

List<String> strlist = new ArrayList<String>() ;

                  Pattern p = Pattern.compile("#([^>]+)>");
                   Matcher m = p.matcher(newstr);


                   while (m.find()) {
                       strto.add(m.group());
                    }



    System.out.println(strtogams);
   String[] strto2 = strto.toArray(new String[20]) ;

Answer

If Java can do look behind assertions, maybe this:

 (?<=#)[^>]+

P.s. – I didn’t look at the other question (should have, but ..)

Leave a Reply

Your email address will not be published. Required fields are marked *