jEdit Community - Resources for users of the jEdit Text Editor
stingy regular expression matching
Submitted by kellner on Monday, 3 April, 2006 - 20:18
Hi,

I'm trying to clean up a document that was automatically converted to LaTeX. The document contains strings like these:

"(\textit{sahaprat}\textit{ī}\textit{tiniyama}). [Reply:] Not even for the piece of ground and the pot is it like this! However, the fact that, if both exist, there is no restriction of the cognition to [only] one image (\textit{ekar}\textit{ū}\textit{papratī}\textit{tiniyamaviraha}),"

(never mind the meaning Smiling)

The idea is to get rid of all the unnecessary instances of \textit{}. So I thought to search for instances of \textit{} that immediately follow one another.

I entered this in the (regexp) search box: \\textit\{(.*?)\}\\textit\{(.*?)\}
and tried replacing it with: \\textit\{$1$2\}

The problem is that the stingy operator ("?") is not stingy enough: apparently the search function looks forward for the second instance of italicization *somewhere* in the document; it doesn't look for instances of *contiguous* italics.

Thus, the regexp also finds:

\textit{some italicized stuff} Oh and here is lots of writing in between! This should not be part of what is found, but it is! \textit{next italicized stuff}.

Somehow I can't bring myself to believe that this is how the regexp should be understood. Or am I barking up the wrong tree?

I also tried a positive lookahead \\textit\{(.*?)\}(?=\\textit\{(.*?)\}), but this produced the same unwanted results.

Any advice would be greatly appreciated,



Thanks in advance,

best regards,
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
stingy works
by ApeHanger on Tue, 04/04/2006 - 07:18
hi kellner,

you have en error in your regexp. the curly braces { and } are no metasigns to a regular expression.

Simply use \\textit{(.*?)}\\textit{(.*?)} and all will work fine.

HTH

.Ape
Non-regex search will work
by John Jameson on Tue, 04/04/2006 - 06:26
If I understand your problem correctly, you only need to use a non-regex replacement:

Search for: }\textit{

Replace with nothing

HTH.
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