This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java REGEX Algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java REGEX Algorithm " Watch "Java REGEX Algorithm " New topic
Author

Java REGEX Algorithm

Deepak Nambiar
Greenhorn

Joined: Jan 17, 2011
Posts: 8
Please explain about the algorithm of regex parser in Java or share any links to that.
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90
Hi,

Regex API is used for pattern matching against pattern specified by the user by regular expressions.

For instance, you need to avoid entering special characters by the end user for any field like First Name or Last Name, then you may make use of java.util.regex API.

Refer here for its API.

For example:
Pattern pattern = Pattern.compile("!@#$%"); // String which you want to restrict
Matcher matcher = pattern.matcher("stringToBeMatched"); // String that needs to be matched (may be entered by user for First Name)

matcher.find(); // returns true if string matched else false is returned

Perform action as per the output is returned.

Thanks,
Ashwini Kashyap | www.infocepts.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 42687
    
  32
You would have to unpack the JVM code to try and work out the algorithm used. Try googling; there are probably sites which show the algorithm.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11744
    
  18

Just wondering why you want to dig into this. One of the points of using a high-level language is that you don't need to know the details - it makes life SO much easier.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
wood burning stoves
 
subject: Java REGEX Algorithm