jEdit Community - Resources for users of the jEdit Text Editor
Restricting regex search matches to single line
Submitted by trenthill on Monday, 9 July, 2007 - 01:37
Hi all,

according to jEdit's help, under "Searching For Text":
"Selecting the Regular expressions check box allows a regular expression to be used in the search string. Regular expressions can match inexact sequences of text that optionally span more than one line."

However, I can't seem to find an option to prevent multi-line matches. Is there something I'm missing? I suppose I could explicitly change the search string to prevent newlines from being matched, but that seems like a rather painful approach for what I find to be a common need.

jEdit version is 4.3pre9.

Thanks, Trent.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
no special option
by Robert Schwenn on Mon, 09/07/2007 - 19:11
It's only the regular expression that controls the matches.

You can exclude or include newlines explict (reg exp = "\n") or You can use "$" to match line end.

Robert
 
Robert Schwenn wrote: > It's
by trenthill on Tue, 10/07/2007 - 00:28
Robert Schwenn wrote:
> It's only the regular expression that controls the matches.

So, to clarify with an example, say I want to find all lines containing consecutive spaces but ignore those that occur at the start of a line. I can do this with grep using this expression:
"^ *[^ ].* "

(I realise there are simpler ways of expressing this, but I'll stick with that for the sake of the argument.)

So, with jEdit, are you saying I need to change it to something like:
"^ *[^ \n][^\n]* "
?

This transformation seems to be rather burdensome to me, especially when expressions become more complex. Does this bother others, or is it just me? Smiling

Thanks, Trent.
 
The example works the same in jEdit
by shlomy on Tue, 10/07/2007 - 10:05
The example you provided above works in jEdit just like in 'grep', because '.' means "anything but a newline".
Maybe you'd like to provide a better example?
 
Not quite the same
by trenthill on Wed, 11/07/2007 - 01:19
shlomy wrote:
> The example you provided above works in jEdit just like in 'grep',
> because '.' means "anything but a newline".

Yes, after some experimenting I see you are right about the '.' - I seem to have gone a little overboard with my transform. However, AFAICT the example still doesn't work like grep due to the '[^ ]'.

So, I believe the minimal transform I needed was from:
"^ *[^ ].* "
to
"^ *[^ \n].* "

So - less of a burden, but still an inconvenience for someone used to thinking in terms of grep.
 
You can run "grep" in the jEdit Console
by shlomy on Wed, 11/07/2007 - 03:22
If you have the Console and ErrorList plugins installed, you can run grep in the System shell of the Console plugin, with the "-H -n" options. These options will make "grep" print the file name and line number with every match it finds, in the same format that many other tools do. This format falls under one of the default "Error patterns" of the Console plugin, so the output of grep will be parsed by the Console and all matches will be added to the ErrorList, using which you can easily jump between the matches.
Interesting, no?
Instead of opening a find dialog and entering the search there, you just do it in the Console and get almost the same behavior, except that the results will be in ErrorList instead of in HyperSearch Results.

Regarding jEdit itself, there is currently no option for the user to limit the search to single lines.
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