• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 40552
825
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");

}
}
}

 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic