Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am not able to dissect the regular expression

 
Swapna latha
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the below tutorial, should help you to understand:
http://www.vogella.com/articles/JavaRegularExpressions/article.html
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation of the Pattern (<-click) class can help you with that.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are far better tutorials available than that one. The Java Tutorials section, for example.
 
Swapna latha
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all. I will follow the tutorials and come back with the answers and doubts

thanks in advance

swapna
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic