Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 03-20-2011, 07:21 AM   #1
seagull
Addict
seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.
 
Posts: 247
Karma: 89950
Join Date: Dec 2009
Device: Amazon Kindle 2
Search/Replace Question

Hello,
In the text that I'm working with all the words that should be italics are encased within underscores, and I was wondering how to replace it with italics, such as:

Find: _text_
Replace: <i>text</i>

Now under a wildcard search _*_ with minimal matching picks them up but I can't find how to replace it. Any help would be appreciated
seagull is offline   Reply With Quote
Old 03-20-2011, 07:49 AM   #2
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
Use code view, In replace, select more, tick regular expression, tick minimal matching

search for
_(.+?)_

repace with
<i>\1</i>
Perkin is offline   Reply With Quote
Advert
Old 03-20-2011, 08:22 AM   #3
seagull
Addict
seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.
 
Posts: 247
Karma: 89950
Join Date: Dec 2009
Device: Amazon Kindle 2
Didn't work but thanks anyway.
seagull is offline   Reply With Quote
Old 03-20-2011, 08:29 AM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,785
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by seagull View Post
Didn't work but thanks anyway.
That was a REGEX type search term, not a wildcard Search term.
theducks is offline   Reply With Quote
Old 03-20-2011, 08:41 AM   #5
seagull
Addict
seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.
 
Posts: 247
Karma: 89950
Join Date: Dec 2009
Device: Amazon Kindle 2
Quote:
Originally Posted by theducks View Post
That was a REGEX type search term, not a wildcard Search term.
I'm aware of that. It didn't work. "Search term was replaced 0 times"
seagull is offline   Reply With Quote
Advert
Old 03-20-2011, 12:00 PM   #6
Faster
Connoisseur
Faster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of lightFaster is a glorious beacon of light
 
Posts: 61
Karma: 12096
Join Date: Sep 2010
Location: Tasmania
Device: Sony PRS 650
Hi,
The Find string is:
Code:
_(.*)_
Replace:
Code:
<i>\1</i>
Faster is offline   Reply With Quote
Old 03-20-2011, 12:28 PM   #7
seagull
Addict
seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.seagull considers 'yay' to be a thoroughly cromulent word.
 
Posts: 247
Karma: 89950
Join Date: Dec 2009
Device: Amazon Kindle 2
Quote:
Originally Posted by Faster View Post
Hi,
The Find string is:
Code:
_(.*)_
Replace:
Code:
<i>\1</i>
Worked perfectly, thanks!
seagull is offline   Reply With Quote
Old 03-20-2011, 12:54 PM   #8
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 696
Karma: 150000
Join Date: Feb 2010
Device: none
You didn't need the ? in the search string, because that's the PERL way of indicating "minimal matching" and in sigil you get that by checking the minimal matching box. In other words, in the earlier search expression it was probably trying to search for a literal "?".
st_albert is offline   Reply With Quote
Old 03-20-2011, 12:56 PM   #9
DMSmillie
Enquiring Mind
DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'
 
DMSmillie's Avatar
 
Posts: 562
Karma: 42350
Join Date: Aug 2010
Location: London, UK
Device: Kindle 3 (WiFi)
Quote:
Originally Posted by Perkin View Post
Use code view, In replace, select more, tick regular expression, tick minimal matching

search for
_(.+?)_

repace with
<i>\1</i>
Quote:
Originally Posted by seagull View Post
Didn't work but thanks anyway.
This had me puzzled, as I'd likely have suggested the same regex, so I checked Sigil's user manual and found this:

"Non-greedy matching cannot be applied to individual quantifiers. Expressions like abc*?dd are not allowed. Use the Minimal matching option to set minimal matching on the whole expression."

So I tried the regex without the "?":

_(.+)_

- and with "Minimal matching" selected, and it worked fine. It was the "?" that was throwing Sigil's regex engine. Worth knowing for future reference.

Edit: Heh! st_albert beat me to it while I was typing, in fewer words and with an explanation.
DMSmillie is offline   Reply With Quote
Old 03-20-2011, 01:09 PM   #10
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 696
Karma: 150000
Join Date: Feb 2010
Device: none
Heh. There are WAY too many dialects of regex for my taste.

By the way, is it true that folks wander around at geek gatherings like PenguinCon, showing each other regular expressions and saying "I'll bet you can't guess what this does"?
st_albert is offline   Reply With Quote
Old 03-20-2011, 01:26 PM   #11
DMSmillie
Enquiring Mind
DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'
 
DMSmillie's Avatar
 
Posts: 562
Karma: 42350
Join Date: Aug 2010
Location: London, UK
Device: Kindle 3 (WiFi)


I've never been to PenguinCon, but it'd almost be worth going just to see if they do!

Most geeky gathering I've ever been to was a W3C technical conference, and if people were comparing regexes, it was by IM or email - absolutely everywhere you looked, inside and outside the conference hall and seminar rooms, people were typing away on their laptops. I rather suspect, though, that most of the stuff they were saying on IM was more along the lines of "Know anywhere we can go for a drink afterwards?"
DMSmillie is offline   Reply With Quote
Old 03-20-2011, 04:29 PM   #12
Jabby
Jr. - Junior Member
Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.
 
Posts: 586
Karma: 2000358
Join Date: Aug 2010
Location: Alabama
Device: Archos, Asus, HP, Lenovo, Nexus and Samsung tablets in 7,8 and 10"
I'm having a bad time with regex. I've read everything about it I can find but I can't seem to figure out how to build a replace string (I can't find any examples).

For instance, in this discussion what does "\1" mean and what does it do?

Can anybody point me to a book or tutorial that uses specific examples to explain Regex? I have found quite a few tutorials that do this for the search function, but none for the the replace string.

Thanks and regards - John

P.S. Long, long ago, in a place far away, I wrote, as we called them then, a "string processor" for the PDP-8. I do understand the concept - its the syntax that befuddles me.
Jabby is offline   Reply With Quote
Old 03-20-2011, 06:12 PM   #13
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
My mistake, it's what I would have used in EditPadPro

The search was looking for _(.*)_
the brackets stores a group - everything in between the _'s

The replace then done the html tags replacing the \1 with whatever was stored

a good site to read through is

http://www.regular-expressions.info/
Perkin is offline   Reply With Quote
Old 03-20-2011, 06:44 PM   #14
DMSmillie
Enquiring Mind
DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'DMSmillie understands when you whisper 'The dog barks at midnight.'
 
DMSmillie's Avatar
 
Posts: 562
Karma: 42350
Join Date: Aug 2010
Location: London, UK
Device: Kindle 3 (WiFi)
Hi Jabby

In the regex:

_(.+?)_

the brackets designate a "backreference" - essentially marking whatever string is matched by the tokens inside the brackets, so that that string can be used as part of the replacement string. You might have several of these in the search string - the first "backreference" would be referenced in the replacement string by "\1", the second by "\2", etc.

In this instance, the regex is looking to match any number of characters ("." = any character, "+" = from 1 to unlimited number, "?" = as few as possible, expanding as needed) between two underscore characters. The brackets designate the text found between the underscore characters as a backreference, for use in the replace string, and since that's the first backreference specified in the regex, it will be referenced as "\1" in the replace string.

The replace string:

<i>\1</i>

specifies a string consisting of "<i>", followed by the text matched in backreference number 1, followed by "</i>".

Someone else might be able to suggest a good online tutorial, Jabby. I'm usually good at understanding technical stuff, but I have to admit I struggled to pick up regex from reading stuff online. What I've found invaluable, though, is a small program called RegexBuddy from JGSoft (the same guys who produce EditPad Pro) - it provides tools to help build regular expressions, and the way you build and view them helps you learn the syntax. It's not free, but it's not expensive either (30 Euros), so might be worth considering.
DMSmillie is offline   Reply With Quote
Old 03-20-2011, 06:51 PM   #15
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
@DMSmillie, the site I linked to was also done by the same team who done EditPadPro, RegexBuddy (and others)
Perkin is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase search and replace? user_none Conversion 24 04-08-2011 03:59 PM
search and replace - drops blanks in replace ? cybmole Conversion 10 03-13-2011 03:07 AM
macro - Search and Replace oldbwl Workshop 17 03-05-2011 01:39 PM
Search and replace in 0.2.0 paulpeer Sigil 7 03-13-2010 11:59 AM
Why no search and replace? charleski Sigil 10 11-24-2009 04:13 PM


All times are GMT -4. The time now is 02:36 AM.


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