You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-user@jakarta.apache.org by Garry Cronin <ga...@oracle.com> on 2002/02/09 20:26:39 UTC
novice question...
Hi!
I'm new to the Jakarta regular expression framework and to regular
expressions in general so please forgive me if this question is niave.
I'll proceed by telling you what I'm attempting to accomplish.
I want to retrieve the list of help topic ids used within our java
source code. The method we use to set an online help topic is as follows:
setHelpTopic("cwwelmyaccess");
So what I want to do is use regexp to find all instances of setHelpTopic
within our code and extract the value enclosed within the double quotes.
In the example provided I want regexp to return the value cwwelmyaccess .
So far I've managed to get regexp to locate all instance of setHelpTopic
by using the following code (I've located the source files I want to
search and am enumerating over theme):
while (enum.hasMoreElements())
{
String pattern = "setHelpTopic.*\".*\"";
try
{
File file = (File)enum.nextElement();
FileInputStream fis = new FileInputStream(file);
StreamCharacterIterator ci = new StreamCharacterIterator(fis);
RE r = new RE(pattern);
boolean matched = r.match(ci, 0);
if (matched == true)
{
numMatches++;
}
}
catch (RESyntaxException e)
{
System.out.println(e.toString());
}
catch (IOException e)
{
System.out.println(e.toString());
}
} // end of while loop
Can somebody tell me how, once located, I can instruct regexp to return
me the value within the double quotes.
Can I get regexp to return a Vector or array of all topics located
within a single source file?
As an aside, you'll see from the code that I'm doing the work in
locating and presenting the source files used within the search. Does
regexp have an API whereby I just have to specify the root directory to
search and perhaps a list of file extensions to filter the search. and
it will do the neccessary work e.g.
String rootDir = "e:\\temp";
String extensions = { ".java", ".txt", ".dat"};
Re re = new RE(pattern, "e:\\temp", extensions);
thanks in advance for your help
- Garry