jEdit Community - Resources for users of the jEdit Text Editor
Help with running 'whole' substitution regular expressions.
Submitted by Aaronc on Monday, 9 January, 2006 - 03:19

Hi there,

I'm fairly new to regular expressions, but I have used jEdit for soem time now. I have search online (google) and also around these forums. So far I haven't found any information for what I am looking for. Perhaps it is my lack of experience with RE if so please forgive my ignorance.

I would like to be able to run regular expressions in jEdit as whole expressions, for example. presently to do a complex find and replace I have to type regular expression argument in the search box, And then place a value in the replace box. The problem with this is that I can't use parenthesis () to back-reference a previously reference string.

Programatical example:

s/(<h2>[^<]*./h2>)/<div>\1<p></p></div>/g

Search for <h2> and any thing in between this and it's close tag to replaced and included as e.g.
find: <h2>Title here</h2>
and replace with: <div><h2>Title here</h2><p></p></div>

regardless of the value for the content between the <h2> and </h2> strings.

I realize that I can use a macro to complete what I am attempting with RE but that defeats my main purpose of learning RE by experimentation.

Thanks Aaron
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Use $1 .. $n in replace box
by John Jameson on Mon, 09/01/2006 - 19:51
If I understand your problem correctly, you want to be able to refer to matches in the replacement string using the find dialogue box, in which case you use $1 etc.

Your example:
s/(<h2>[^<]*./h2>)/<div>\1<p></p></div>/g

becomes:
Search box: (<h2>[^<]*./h2>)
Replace box: <div>$1<p></p></div>

HTH.
 
Hey thats great!
by Aaronc on Thu, 12/01/2006 - 23:18

Thanks for that, I had a hard time finding documentation that refered to what I was trying to do. It's not quite how I expected it to work. I was kinda hoping that there was a in build regular expression parser that I could just pass a RE to, without having to use find and replace.

I appreciate your help!

User login
Browse archives
« November 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   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300