[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-regexp-user
Subject:    RegExp bug, or weirdness
From:       Alex Muc <alex.muc () utoronto ! ca>
Date:       2000-10-25 4:04:03
[Download RAW message or body]


Hi,

I've started using the Jakarta RegExp package.  Most of my experience
has been good so far, but I'm running up against the following strange
behaviour and I'm not sure if it is my RE or the input text or some
bug/limitation in the RE package itself.  Hopefully you'll be able to
help me out.

I'm trying to match against various constructs in some Java source files
and JSP files.  My task at hand right now is to match the following code
construct:
...
Utils.getValue(h, "<string>");
...
Where "<string>" is some Java string without any spaces in it.
The above bit of code usually appears on a line by itself (although the
parsing that I'm currently doing strips out all line feeds.  The above
bit of code appears more than once in the source file with varying
"<string>".

I'm trying to match the expression using the following RE:
  re = new RE("Utils\\.getValue\\(h,[:space:]*\"[:alnum:]*\"\\);");
Note: That the double backslashes escape the period, and bracket
characters, I'm not sure if this is exactly the right escaping method,
but it seems to work.  Please correct me if I'm wrong.

Here's where the weirdness begins:  The following code block is what I'm
trying to do with the RE over the source file.  As you can see it loops
repeatedly until it runs out of matches.
  re = new RE("Utils\\.getValue\\(h,[:space:]*\"[:alnum:]*\"\\);");
  int index = 0;
  while (re.match(pc, index)) {
   String param = re.getParen(0);
   index = re.getParenEnd(0);
   re = new RE("\"\\S*\"");
   re.match(param);
   param = re.getParen(0);
   param = param.substring(1, param.length() - 1);
   p.addParameter(param, p.TYPESTRING);
  }

The first iteration of the loop works fine, the RE returns
Utils.getValue(h, "depth");
which is the first occurrence of the RE in the source file.  The second
iteration it goes goofy and matches instead, any string in quotes in the
source file which in my case happens to be the string "shallow".  I've
attached the source file so you can see exactly what I'm working with.

I don't understand why the loop is matching correctly on the first
iteration and then matching any quoted string on subsequent iterations
of the loop.  Any help you can offer me to help me solve the problem
would be appreciated.
I've tried working with the RE in the Demo applet that ships with the
RegExp package and in the applet it seems to work fine.

Thanks
Alex.

["AreaDelete.jsp" (application/x-unknown-content-type-jsp_auto_file)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic