how to read string part in java
        Posted  
        
            by Gandalf StormCrow
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gandalf StormCrow
        
        
        
        Published on 2010-04-14T08:54:04Z
        Indexed on 
            2010/04/14
            9:23 UTC
        
        
        Read the original article
        Hit count: 238
        
Hello everyone, I have this string :
<meis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" uri="localhost/naro-nei" onded="flpSW531213" identi="lemenia" id="75" lastStop="bendi" xsi:noNamespaceSchemaLocation="http://localhost/xsd/postat.xsd xsd/postat.xsd">
How can I get lastStop property value in JAVA?
This regex worked when tested on http://www.myregexp.com/
But when I try it in java I don't see the matched text, here is how I tried :
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class SimpleRegexTest {
    public static void main(String[] args) {
        String sampleText = <meis xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" uri=\"localhost/naro-nei\" onded=\"flpSW531213\" identi=\"lemenia\" id=\"75\" lastStop=\"bendi\" xsi:noNamespaceSchemaLocation=\"http://localhost/xsd/postat.xsd xsd/postat.xsd\">";
        String sampleRegex = "(?<=lastStop=[\"']?)[^\"']*";
        Pattern p = Pattern.compile(sampleRegex);
        Matcher m = p.matcher(sampleText);
        if (m.find()) {
            String matchedText = m.group();
            System.out.println("matched [" + matchedText + "]");
        } else {
            System.out.println("didn’t match");
        }
    }
}
© Stack Overflow or respective owner