jEdit Community - Resources for users of the jEdit Text Editor
Regular expression in macro doesn't work
Submitted by Anonymous on Tuesday, 23 December, 2003 - 23:48
Hi, Macros like below
 
>>>>
    Pattern p = Pattern.compile("*.\(([0-9]+)\).*");
    lineText = textArea.getLineText(line);
    Matcher m = p.matcher(lineText);
>>>>

or 

>>>>
gnu.regexp.RE re = new gnu.regexp.RE("^(\*.)\\t(\*.)\\t(\*.)$");
lineText = textArea.getLineText(line);
gnu.regexp.REMatch match = re.getMatch(lineText);
lineText = "<1>=" + match.toString(1) + "<2>=" + 
   match.toString(2) + "<3>=" + match.toString(3);
>>>>
don't work. Parsing fails on both. Does it mean I can't use any regular expressions in macros or am I doing something wrong? Stan Berka
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Another expression not working
by Anonymous on Thu, 10/03/2005 - 10:31
Hi,

I tried to delete unnecessary lines from a file. I recorded a macro, by first searching for a ^((?!expression).)*$ then deleting the line. Then I edited the bsh to do this in a loop. The code I got is

SearchAndReplace.setSearchString("^((?!expression).)*$");
SearchAndReplace.setAutoWrapAround(false);
SearchAndReplace.setReverseSearch(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(true);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
while (SearchAndReplace.find(view))
textArea.deleteLine();

When a line is deleted, the whole file shifts up and the next line takes its place. But the search is executed not on this line, but the one after that! So it skips every second line!
OK, I could do it by specifying setAutoWrapAround(true) but that sometimes throws an exception (I will post it as a bug) and I am really interested in why doesn't the code above work.
 
Similar problems
by mabra on Wed, 09/08/2006 - 22:27
Hi !

I have had similar problems, but only inside a XInsert module. As a workaround, I defined my patterns as globals variables in the startup module. I feel, this a very dirty workaround - totally fixed to one case - but it helped me.
My expression was:

"([ ]{0,}Processe.*\n)|([ ]{0,}[0-9{1,}[ ]{0,}Processe.*\n)"

Additionally, even using regex in a usual search&replace task, I had other problems too. I tried to replace the caret character and no expression was able to find it at the end of a line. A simple search found it. I have not found a solution for this.

It may be, so my newbie/small java-based knowledge, that's due to using the BeanShell. I had other problems, for example, replacing double backslashes, and I had to use the following ugly thing to replace two backslashes against one:

temp = badPath.replaceAll("\\\\\\\\", "\\\\");

Just my notes Eye-wink

Best regards,
Manfred
 
 
 
 
 
Why not change the RE to matc
by Skeeve on Fri, 30/09/2005 - 11:04
Why not change the RE to match the \n too and let "Replace All" do the work?

You might also want to try to search backwards, starting at the end of your buffer.
Not sure this will work...
by Anonymous on Wed, 02/06/2004 - 02:56
But try:

re = new RE("[EXPRESSION]", 0, RESearchMatcher.RE_SYNTAX_JEDIT);


You might have to specify a parsing flavor.

-Pete
User login
Browse archives
« April 2024  
MoTuWeThFrSaSu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82348
Context Free Art (*.cfdg)   0.31   46055
JBuilder scheme   .001   18495
BBEdit scheme   1.0   18116
ColdFusion scheme   1.0   18024
R Edit Mode - extensive version   0.1   17473
Advanced HTML edit mode   1.0   16206
Matlab Edit Mode   1.0   16068
jEdit XP icons   1.0   15229
XP icons for jEdit   1.1   14293