Hi everybody.

I am a student in computers at the Hebrew University in Jerusalem.

I started to work with Java - and working with Product Version:

NetBeans IDE 6.5
Java: 1.6.0_11; Java HotSpot(TM) Client VM 11.0-b16
System: Windows XP version 5.1 running on x86; Cp1252; en_US

I have an urgent question:

If I look for a patern in a scanner and I find it - How do I know the position in the scanner? the pattern helps me to be near data I know is afterward but i can not find a pattern or I dont know how it looks. so I look for the pattern (can be date) and I know that my data is afterwards and I want to collect from that position only for a number of bytes or until the end of a sentence..

I can't find any command - the start() and end() from the scanner are private. or can I access them?

Here is a function I wrote in Java:

private static String find(Scanner sc, String pattern) {
    String Stoken;
    while (( Stoken = sc.findInLine(pattern)) == null) {
        if (sc.hasNextLine()) {
            sc.nextLine();           
        } else {
            return null;
        }
    }  
    return Stoken;
}

Thanks

You can get that info from the MatchResult returned by the match() method.

It would probably be a lot easier to add a capturing group to your match pattern for the data you want to collect and extract it as part of the match result. More info on capturing groups (and regex in general) here: http://java.sun.com/docs/books/tutorial/essential/regex/groups.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.