File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes I am not able to dissect the regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I am not able to dissect the regular expression" Watch "I am not able to dissect the regular expression" New topic
Author

I am not able to dissect the regular expression

Swapna latha
Ranch Hand

Joined: Dec 18, 2011
Posts: 70
I have got a regular expression in my code which checks for special characters. But i could not able to dissect it how its working ?

^[^:>#*]+|([^:>#*][^>#*]+[^:>#*])$


Thanks in advance

swapna
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Check the below tutorial, should help you to understand:
http://www.vogella.com/articles/JavaRegularExpressions/article.html
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

The API documentation of the Pattern (<-click) class can help you with that.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

Just like any programming task, try and break it down into smaller parts that you can understand. Also, tell us where exactly you get lost. Surely some parts of it make sense...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37985
    
  22
There are far better tutorials available than that one. The Java Tutorials section, for example.
Swapna latha
Ranch Hand

Joined: Dec 18, 2011
Posts: 70
Thanks to all. I will follow the tutorials and come back with the answers and doubts

thanks in advance

swapna
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37985
    
  22
You’re welcome

That regex seems to have repeated elements. If you work out what the repeating element in square brackets means, you are a long way towards solving the whole problem.
Swapna latha
Ranch Hand

Joined: Dec 18, 2011
Posts: 70
I have learned the basics of regular expression. Thanks to all. I got one problem with my regex.


My regex is written in such a way that it should not allow alpha numeric, and special characters. Thats fine, but its failing in one scenario for targetPage and that is Prestige$%$lll.jsp. How to make sure that it should work.
I am getting the following error:




thanks in advance

swapna
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7542
    
  18

Swapna latha wrote:My regex is written in such a way that it should not allow alpha numeric, and special characters. Thats fine, but its failing in one scenario for targetPage and that is Prestige$%$lll.jsp. How to make sure that it should work.

Fairly obviously, by making sure that it 'understands' the "%nn" syntax.

My suggestion: write a little program that does this using ONLY standard String methods, and then translate it to a regex. You may find that your program is actually faster than a regex; and for something complicated like this, it's highly likely to be more readable too.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am not able to dissect the regular expression
 
Similar Threads
How can I add error handling facilities to this code?
Validating The Date String
Designing Around UNIX File /etc/services
help requested with regular expressions
regular expression which doesnt alllow *