Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-13-2010, 02:43 PM   #1
Fabe
Dylanologist
Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.
 
Fabe's Avatar
 
Posts: 200
Karma: 146754
Join Date: Apr 2010
Location: Hanover, New Hampshire, USA
Device: none/all/any
Another Grep Question

OLD TEXT:
<p>Section 1: Text text text ...</p>

DESIRED RESULT:
<p>Section 1:</p>

<p>Text text text ...</p>

FIND:
<p>Section \d:

REPLACE:
<p>Section ??:</p>\r\r<p>

RETURNS:
<p>Section ??:</p>

<p>Text text text ...</p>

The red question marks represent a number of unsuccessful tries on my part. I wish the replace to use the found data so my numbers increase appropriately. In some instances they go into double digits (e.g. Section 12: )

Can anyone help? Thanks. - Fabe
Fabe is offline   Reply With Quote
Old 12-13-2010, 03:55 PM   #2
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by Fabe View Post
OLD TEXT:
<p>Section 1: Text text text ...</p>

DESIRED RESULT:
<p>Section 1:</p>

<p>Text text text ...</p>

FIND:
<p>Section \d:

REPLACE:
<p>Section ??:</p>\r\r<p>

RETURNS:
<p>Section ??:</p>

<p>Text text text ...</p>

The red question marks represent a number of unsuccessful tries on my part. I wish the replace to use the found data so my numbers increase appropriately. In some instances they go into double digits (e.g. Section 12: )

Can anyone help? Thanks. - Fabe
There's a number of different ways but this should work:
Code:
Find: <p>(Section \d+:) ([^<]+)</p>
Replace: <p>\1</p><p>\2</p>
Make sure you tick the "Minimal matching" checkbox in the options.

Last edited by kiwidude; 12-13-2010 at 04:19 PM.
kiwidude is offline   Reply With Quote
Advert
Old 12-13-2010, 04:16 PM   #3
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
A translation if needed for your future use and tweaking. I've added a space here and there below just to stop the post displaying smilies without a code section so : ) instead of this

The ( ) brackets around parts in the Find expression mean grab the bits that match inside the brackets into a "group" for use in the Replace expression. Each () pair can be retrieved incrementally in the replace using \1 \2 \3 etc.

So the (Section \d+: ) means find anything that matches "Section " followed by digits (the \d) of which there are one or more (the +) then a ":" colon.

Then in the replace the <p>\1</p> means grab the first ( ) group contents which will be the result of matching (Section \d+: ) in this case, and puts inside <p></p> tags.

The second part of the find is ([^<]+). As above this tells you the match will be put into a group, that you can access in replace using \2.

The [ ]+ says grab one or more characters it can find specified within the square brackets. If you know you are after certain characters you could do [a-z]+ for instance to get only alphabetic letters. However your text likely will contain letters, numbers, spaces, commas, quotes, all sorts of stuff. So rather than actually listing all of the possible values in this case I have said match [^<]+ which means until it reaches not (^) a < character. Effectively it means any characters until it reaches the < of the closing </p> tag.

Hope some of that makes sense... Oh yeah - make sure you tick the "Minimal matching" checkbox in the Options too.

Last edited by kiwidude; 12-13-2010 at 04:18 PM.
kiwidude is offline   Reply With Quote
Old 12-13-2010, 04:41 PM   #4
Fabe
Dylanologist
Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.Fabe has survived committing the World's Second Greatest Blunder.
 
Fabe's Avatar
 
Posts: 200
Karma: 146754
Join Date: Apr 2010
Location: Hanover, New Hampshire, USA
Device: none/all/any
Kiwidude, thank you so much. I only had to add line feeds to the replace line like this: <p>\1</p>\r\r<p>\2</p>\r to get the correct result. I was floundering, I'm so glad I asked and you were on line. Thanks again. - Fabe
Fabe is offline   Reply With Quote
Old 12-13-2010, 04:51 PM   #5
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by Fabe View Post
Kiwidude, thank you so much. I only had to add line feeds to the replace line like this: <p>\1</p>\r\r<p>\2</p>\r to get the correct result. I was floundering, I'm so glad I asked and you were on line. Thanks again. - Fabe
Glad to help. Sigil will automatically reformat with line feeds when you flick between book/code view anyways.
kiwidude is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grep Find & Replace Fabe Sigil 3 12-06-2010 12:00 PM
using the Calibre GREP to format chapters in RTFs raingod Amazon Kindle 1 10-08-2010 02:52 AM
Classic Few Nook Question and Question on Nook 3G vs WiFi blackonblack Barnes & Noble NOOK 4 07-02-2010 02:07 AM
Looking for another reader question and PRS-600 question lilpretender Which one should I buy? 9 10-24-2009 04:02 AM
Hello And A Question ChopperHarris Introduce Yourself 6 08-25-2009 05:33 PM


All times are GMT -4. The time now is 05:59 PM.


MobileRead.com is a privately owned, operated and funded community.