wood burning stoves 2.0*
The moose likes Other Languages and the fly likes pattern matching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "pattern matching" Watch "pattern matching" New topic
Author

pattern matching

etika ahuja
Greenhorn

Joined: Apr 13, 2011
Posts: 8


the pattern does not get matched if the url contains " ? " why so ?

what is the solution to this problem
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30069
    
149

The "?" has special meaning in regular expressions. You need to escape it by putting a "\" before it. (really two because the \ is a special character in Java and needs escaping itself.)

In the regular expression world, ? means 0 or 1 of the previous character.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
etika ahuja
Greenhorn

Joined: Apr 13, 2011
Posts: 8
import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.regex.*;

class pattern
{
public static void main(String[] args)
{
String temp="http://railsforum.com/viewtopic.php\\?id=38039";
String par="http://railsforum.com/viewtopic.php\\?id=38039";
Pattern pat= Pattern.compile(par);
Matcher mat= pat.matcher(temp);

if(mat.find())
{
System.out.println("match found");

}
}
}


it is still not be able match the pattern
etika ahuja
Greenhorn

Joined: Apr 13, 2011
Posts: 8
i got the answer..
import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.regex.*;

class pattern
{
public static void main(String[] args)
{
String temp="http://railsforum.com/viewtopic.php?id=38039";
String par="http://railsforum.com/viewtopic.php\\?id=38039";
Pattern pat= Pattern.compile(par);
Matcher mat= pat.matcher(temp);

if(mat.find())
{
System.out.println("match found");

}
}
}

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: pattern matching
 
Similar Threads
display unicode characters in midlet
Java DB - Delete all records in a table.
one-to-many relation
Java Data and time pattern
Automatic Optimistic Concurrency