BeanShell complains on 'quotemeta', and I wasn't able to find a reference in
the jEdit source tree. Isn't it a perl internal function and not part of
BeanShell or its namespace? Also, jEdit searches in multiline mode, so the
pattern does work at the end of a line (However, it will not work if the
sole occurrence of the searched term is at the end of the buffer).
Thanks for your suggestions; I'll post a fixed version later.
[mailto:jedit-devel-admin@... Behalf Of mike dillon
Sent: Wednesday, February 28, 2001 12:53 PM
To: jEdit developers' list
Subject: [ jEdit-devel ] RE: [ jEdit-users ] goto global declaration of
variable macro listing and question
the regexp you use to ensure that a full word is found is slightly flawed.
basically you add /[\s\W]+/ to the end of whatever the current word is under
the cursor. this won't work at the end of a line. also, /[\s\W]+/ is
just use /\W+/. actually, there's no reason to continue searching one you've
found a single non-word character, so drop the "+". you might want to try
adding /(?:^|\W)/ to the beginning and /(?:\W|$)/ to the end of the current
pattern. since the first and last characters of the original pattern are
guaranteed to be \w characters, this is basically equivalent to "\<PAT\>",
which is what you really want anyway.
now that i think about it, this will still have a problem if PAT starts or
with a noWordSep character that is not also a \w character (the usual case
such characters). so, the real solution is:
noWordSep = quotemeta(buffer.getProperty("noWordSep"));
text = textArea.getSelectedText();
class = "[^\\w" + noWordSep + "]";
pat = "(?:^|" + class + ")" + text + "(?:$|" + class + ")";
quoting from 'perldoc -f quotemeta':
Returns the value of EXPR with all non-
alphanumeric characters backslashed. (That is,
all characters not matching `/[A-Za-z_0-9]/' will
be preceded by a backslash in the returned string,
regardless of any locale settings.)