aspose file tools
The moose likes Java in General and the fly likes need java regex pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "need java regex pattern" Watch "need java regex pattern" New topic
Author

need java regex pattern

Kumar Muthiah
Greenhorn

Joined: Apr 17, 2006
Posts: 3
Hi,

could someone please provide me with a regex pattern

My requirement is as follows:

I need to get method comments from java source file, by searching a method. For this i use java reflection to get method prototype. Then I construct a regular expression from the method prototype, to find the method in the source code.

The prototype looks like as follows:

public void contactAddMultitypeEntry(String, String[], EntryType[])

To construct the regular expression, i need to use String.replaceAll() method to replace blank spaces, ',','(' to form the regular expression as follows.
public*void*contactAddMultitypeEntry\\(String(\\w+)String\\[\\](\\w+)EntryType\\[\\](\\w+)\\)(\\w+)


...to match the method in the following source code.

My worry is how to replace the '[', ']', '(' and ')' symbols with the regular expression pattern, using replaceAll() method. If at all i manage to replace, will the regular expression will work?

Source Code:
/**
* Adds a multitype entry to the Contacts.
*
* @param name Name of the entry.
* @param number array of numbers
* @param type array of types. (EntryType.HOME, EntryType.PRIVATE)
* @pre All arrays must be of the same size and unit must be in BERbug.
* @eg phone1.berbug.contactAddMultitypeEntry("Twenty digs", new String[] {"9999","12345678901234567890"}, new EntryType[] {EntryType.MAIN, EntryType.WORK});
* @exception TestException if the Contact was full, name more than 20 char, EntryType talkgroup is not the only record, size of array is not same and error when writing to SIM
*/
public void contactAddMultitypeEntry(String name, String[] number, EntryType[] type) throws TestException {
}

I need this in a project on urgent basis.

Thanks!
[ April 17, 2006: Message edited by: Kumar Muthiah ]
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Where you have "*" in your regex, you should have "\\s+" to match one or more whitespace characters. You also need to allow for whitespace before the parameter names. Try this:
Kumar Muthiah
Greenhorn

Joined: Apr 17, 2006
Posts: 3
Thanks Alan Moore. It helped a lot.
 
I agree. Here's the link: jrebel
 
subject: need java regex pattern
 
Similar Threads
split finding strange "null"
Need a disconnected resultset
Regular Expression Help
java parsing using regular expression