rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Apr 16
2009

Java Regex Matching digg

Took me half a day to figure out matcher.find() had to be called first. Gaah!

RegexTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
 
public class Tester {
    public static void main(String args[]) 
    {
        Pattern pattern = Pattern.compile("name=\"QTime\">(\\d+)</int>");
        Matcher matcher = pattern.matcher("<response><lst name=\"responseHeader\">" + 
            "<int name=\"status\">0</int><int name=\"QTime\">2</int></lst></response>");
 
        try {
            if(matcher.find()) {
                System.out.println(matcher.group(1));
            }
        }
        catch (Exception e) {
            System.out.println("Couldn't find QTime");
        }
    }
}

P.S. I love Python

4 Responses (rss) (trackback)

#1

Shashi

April 18th, 2009 at 7:45 am

Why? Google.com is banned out there? ;-)

#2

Pravin Paratey

April 25th, 2009 at 12:14 am

:P

#3

Santosh

May 8th, 2009 at 2:24 am

Hey, recalling our mysites days!! regex and pattern matching. :))

#4

Pravin Paratey

May 8th, 2009 at 2:51 am

Haha :P Those were some lovely days :)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it! [Read More]
Jan
21

Writing a spider in 10 mins using Scrapy

I came across Scrapy a few days back and have grown to really love it. This tutorial will illustrate how you can write a simple spider using Scrapy to scrape data off Paul Smith. All this in 10 minutes. [Read More]

Featured Projects

Indic to English Transliterator

Indic to English Transliterator

Transliteration is the process of converting a word from one language to another while retaining its phonetic characteristics. This application lets you convert a word from any major Indian language (currently supports Hindi, Marathi, Sanskrit and Bengali) to English.

[Read More]

NLP classes for PHP

NLP classes for PHP

This is an ongoing project to develop a set of classes for Natural Language Processing. Some code would be ported from the NLTK project.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.