Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Help in Regular expression using java (http://www.go4expert.com/forums/help-regular-expression-using-java-t3713/)

vithasekar 2Apr2007 10:58

Help in Regular expression using java
 
I want to do pattern matching using java.

My string is (a<b)

I tried with the following patterns.
[(][a][<][b][)]$

and

[(][a][/<][b][)]$

but these patterns doesn't match.
can any one tell me how to match operators like < , >, <=, >=, + ..


Thank u..

pradeep 2Apr2007 12:33

Re: Help in Regular expression using java
 
Try this
Code:

\([a]<[b]\)
Operators are matched like normal characters, for more info try http://regularexpressions.info

vithasekar 2Apr2007 13:44

Re: Help in Regular expression using java
 
if(String.matches("\([a]<[b]\")

I am getting error: unrecognized escape sequence.

shabbir 2Apr2007 13:56

Re: Help in Regular expression using java
 
You have not copied the things correctly. You are missing the end bracket.

vithasekar 2Apr2007 14:06

Re: Help in Regular expression using java
 
After that also, I am getting the same error

if(strng.matches("\([a]<[b]\)")

pradeep 2Apr2007 16:39

Re: Help in Regular expression using java
 
Here's an example of using Regular Expressions in Java

Code: Java

// Compile regular expression
    String patternStr = "b";
    Pattern pattern = Pattern.compile(patternStr);
   
    // Determine if there is an exact match
    CharSequence inputStr = "a b c";
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.matches(); // false
   
    // Try a different input
    matcher.reset("b");
    matchFound = matcher.matches();         // true
   
    // Determine if pattern matches beginning of input
    matchFound = matcher.lookingAt();       // false
 


vithasekar 2Apr2007 17:46

Re: Help in Regular expression using java
 
Thank u sir. It's working.

sssrsl 1May2007 21:20

Help in Regular expression using java
 
Hi

I need to check for a PO Box addresses in a string. I should not allow a pobox in a address Line. For that I need a pattern and willl match this pattern with my string

Ex:***** something like this ******
Pattern poBoxPattern = Pattern.compile("\\bp\\s*\\d") ....
Matcher matcher = poBoxPattern.matcher(locationAddressStreet);
if(matcher.find()){

}


So, could anyone help me with making the pattern.
My pattern should recognize sub strings like...
1. po 123 ( meaning: po followed by any integer/integers )
2. p o 123
3. p.o. 123
4. p. o. 123
5. po box
6. po box
7. p o box
8. p o 123

Note: "po sometext" or "p o sometext" should not be recognized.

Any help is truly appreciated.

Thanks
Sai

shabbir 1May2007 21:29

Re: Help in Regular expression using java
 
sssrsl, have a separate thread for the query as that will give more visibility to experts as well as help others to search.

sssrsl 1May2007 21:38

Re: Help in Regular expression using java
 
I did. Thanks, for the suggestion.


All times are GMT +5.5. The time now is 03:27.