• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pattern matching

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

what is the solution to this problem
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
etika ahuja
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");

}
}
}

reply
    Bookmark Topic Watch Topic
  • New Topic