Domanda

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]) ;
È stato utile?

Soluzione

If Java can do look behind assertions, maybe this:

 (?<=\#)[^>]+

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top