MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Sigil (https://www.mobileread.com/forums/forumdisplay.php?f=203)
-   -   RegEx REPLACEMENT: Help needed! (https://www.mobileread.com/forums/showthread.php?t=67704)

LARdT 12-31-2009 08:44 AM

RegEx REPLACEMENT: Help needed!
 
Does anyone now which is the notation for the replacement operator?

%1 and $1 do not seem to work


I want this:
Code:

<div class="s5" id="calibre_toc_2">
<p class="calibre2">I. PERDIDOS EN EL COSMOS</p>

turned into:
Code:

<div class="s5" id="calibre_toc_2">
<h3 class="calibre2">I. PERDIDOS EN EL COSMOS</h3>

With:
Code:

<div class="s5" id="calibre_toc_[0-9]">\n\s*<p class="calibre2">([\(\Ñ\).a-zA-Z0-9\-_\s\c]*)</p>
I can select all the ocurrences in the file but cannot do any replacement as far as the usual notation does not seem to work

Valloric 12-31-2009 09:12 AM

It's \#.

I really need to write a wiki page for the regex syntax... but I'm slightly reluctant since I'll probably be replacing the currently used engine with PCRE.

Anyway, you can see the upstream documentation on the regex engine that Sigil uses here.

LARdT 12-31-2009 09:24 AM

I read the link before and as far as I remember
there is no reference to \# nor replace.

¿could you please use it in the example I'm working on?
I cannot make it work

EDIT:

No need to. I've figured out myself. Odd notation though.
Thanks anyway.

Jellby 12-31-2009 09:46 AM

I think it means using \1, \2, etc. instead of %1 or $2...

sircastor 12-31-2009 01:16 PM

Quote:

Originally Posted by Valloric (Post 718954)
but I'm slightly reluctant since I'll probably be replacing the currently used engine with PCRE.

Excellent. This is the best news I've heard today.

Valloric 12-31-2009 03:57 PM

Quote:

Originally Posted by sircastor (Post 719252)
Excellent. This is the best news I've heard today.

Really? You care that much about the possibility of the internal regex engine switching to PCRE? I'd love to know why.

I mean, I know why I care about it, but I'm interested in why are you so excited about the prospect. Knowing the reason would give me more perspective.

rogue_ronin 12-31-2009 06:28 PM

Quote:

Originally Posted by Valloric (Post 718954)
I'll probably be replacing the currently used engine with PCRE.

Wa-hoo!

The universe is kind today!

m a r

ps: I'm a NoteTab dork, and it uses PCRE.

LARdT 12-31-2009 09:00 PM

Well, I suppose you are thinking on development issues but I've consulted the Wiki comparison between RegeX ENGINES and Qt seemed to be the less powerful and flexible:

http://en.wikipedia.org/wiki/Compari...ession_engines

Anyway it has done the job perfectly after the initial surprise because of the non-standard (if there is such thing as a standard for RegEx) notation.

Valloric 12-31-2009 09:36 PM

Quote:

Originally Posted by LARdT (Post 719690)
Well, I suppose you are thinking on development issues but I've consulted the Wiki comparison between RegeX ENGINES and Qt seemed to be the less powerful and flexible

Well the same reasons too. It's more powerful. I just thought maybe you wanted a specific feature from PCRE.

I'm also fairly sure PCRE will be much faster. I'll have to profile that to be sure, but I have a feeling.

Quote:

Originally Posted by LARdT (Post 719690)
Anyway it has done the job perfectly after the initial surprise because of the non-standard (if there is such thing as a standard for RegEx) notation.

Actually that's me, not Qt. I like the "\#" notation, it comes from sed. I like sed. :)

When I get around to creating an options screen, I might make it user-selectable.

LARdT 01-01-2010 01:41 AM

Quote:

Originally Posted by Valloric (Post 719717)
Actually that's me, not Qt. I like the "\#" notation, it comes from sed. I like sed. :).

Aaah! Gotcha! I knew it in my bones that wasn't very standard :smack:

Now that I've you on the line, lets talk about SIGIL "philosophy": I've been thinking about what you said about the program sticking to the "Editor" tool concept. Let say that the program has now 2 clear edition "layers":
- One "high level", user friendly, WYSISWYG related layer.
- Other "low level" advanced user, CODE related layer.
Perhaps the program will become an original & powerful tool if it develops functionalities in an in-between "layer". For example: beign able to manage a library of personal CSS styles to apply them over existing CSS styles generated by conversion software.

sircastor 01-01-2010 02:55 AM

Quote:

Originally Posted by Valloric (Post 719444)
Really? You care that much about the possibility of the internal regex engine switching to PCRE? I'd love to know why.

I mean, I know why I care about it, but I'm interested in why are you so excited about the prospect. Knowing the reason would give me more perspective.

When it comes down to it, it was really a matter of me simply being very familiar with PCRE regex, and not really with any other library. It's just a pain when you have to go look up something.

(I just realized that "PCRE regex" is a bit redundant)

Jellby 01-01-2010 06:48 AM

Quote:

Originally Posted by LARdT (Post 719828)
Aaah! Gotcha! I knew it in my bones that wasn't very standard :smack:

It's used in vim too, and I like vim :D

Sabardeyn 01-04-2010 08:25 PM

just, FYI, their is a link to a regex tutorial for python (but including references to other flavors of regex expressions) under software called REGEX BUDDY. While it is a little steep for the average newbie, someone with programming experience should be able to handle it pretty well.

I cannot remember the exact name of the site, thus the indirect reference.


All times are GMT -4. The time now is 06:44 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.