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 { }
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: