Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 06-04-2020, 07:52 PM   #1
d351r3d
Enthusiast
d351r3d began at the beginning.
 
Posts: 48
Karma: 10
Join Date: Aug 2017
Device: none
Regex Beginning and End of Tag

Can Regex understand the end of a line or the beginning of a line that has text on it? I want to be able to insert something at the beginning of each line where the text starts and at the end of the line where the text ends. I'm thinking Regex can do this. I've used it so far and it's a very cool guy.

My process is this:

I copy pasta lots of text into a text editor, then I copy pasta that into Sigil and I'd like to use regex to do some hefty formatting inside of Sigil.

Last edited by d351r3d; 06-04-2020 at 07:56 PM.
d351r3d is offline   Reply With Quote
Old 06-04-2020, 09:19 PM   #2
The_book
Zealot
The_book began at the beginning.
 
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
I think it is ^ and $ in regex. ^ means the start of a line and $ means the end.
What you want is the end of a line or the beginning of a line that has text on it, which I think close to ^.+$
The_book is offline   Reply With Quote
Advert
Old 06-05-2020, 04:05 AM   #3
d351r3d
Enthusiast
d351r3d began at the beginning.
 
Posts: 48
Karma: 10
Join Date: Aug 2017
Device: none
Quote:
Originally Posted by The_book View Post
I think it is ^ and $ in regex. ^ means the start of a line and $ means the end.
What you want is the end of a line or the beginning of a line that has text on it, which I think close to ^.+$
If you just put in "find":
Code:
^.+$
Could you put in "replace":
Code:
<p></p>
and that would turn:
Code:
I really like sandwiches!
Into:
Code:
<p>I really like sandwiches</p>

Last edited by d351r3d; 06-05-2020 at 09:06 AM.
d351r3d is offline   Reply With Quote
Old 06-05-2020, 09:52 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,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
NO!

You did not insert any captured data (the \1 )

<p>\1</p>

You did not even CAPTURE any data
Put a ( ) pair around the part you want to capture (if there is a real ( or ) in the template: escape those: \( or \)
theducks is offline   Reply With Quote
Old 06-05-2020, 10:17 AM   #5
d351r3d
Enthusiast
d351r3d began at the beginning.
 
Posts: 48
Karma: 10
Join Date: Aug 2017
Device: none
Quote:
Originally Posted by theducks View Post
NO!

You did not insert any captured data (the \1 )

<p>\1</p>

You did not even CAPTURE any data
Put a ( ) pair around the part you want to capture (if there is a real ( or ) in the template: escape those: \( or \)
So you can't do what I'm trying to do with Regex? Like regex can't be like "oh that's the beginning of a line with content, let me just put something before that and there's the end of a line, let me just put something after that line with content."
d351r3d is offline   Reply With Quote
Advert
Old 06-05-2020, 01:15 PM   #6
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,474
Karma: 145525534
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by d351r3d View Post
If you just put in "find":
Code:
^.+$
Could you put in "replace":
Code:
<p></p>
Quote:
Originally Posted by theducks View Post
NO!

You did not insert any captured data (the \1 )

<p>\1</p>

You did not even CAPTURE any data
Put a ( ) pair around the part you want to capture (if there is a real ( or ) in the template: escape those: \( or \)
Quote:
Originally Posted by d351r3d View Post
So you can't do what I'm trying to do with Regex? Like regex can't be like "oh that's the beginning of a line with content, let me just put something before that and there's the end of a line, let me just put something after that line with content."
What he is saying is you need to capture the data first and then place it in the replace string. See the brackets around the find string and the \1 in the replace string.

HOWEVER: Please note that this will match EVERY line in your document no matter what it is.

In the case of your sample code:

Code:
(^.+$)
Could you put in "replace":
Code:
<p>\1</p>
I would recommend either pasting your text into a blank text file or using Notepad++ or equivalent to do the replacement in the text before pasting it into Sigil. Notepad++ can use the same find/replace strings making easier for me.

Last edited by DNSB; 06-05-2020 at 09:37 PM.
DNSB is online now   Reply With Quote
Old 06-05-2020, 01:55 PM   #7
d351r3d
Enthusiast
d351r3d began at the beginning.
 
Posts: 48
Karma: 10
Join Date: Aug 2017
Device: none
[QUOTE=DNSB;3996728]
Quote:
Originally Posted by d351r3d View Post
If you just put in "find":
Code:
^.+$
Could you put in "replace":
Code:
<p></p>

I get it now. It selects the entire line and then you can modify the line that's saved. Sorry this is new and it's like a puzzle. Thanks for clarifying.


What he is saying is you need to capture the data first and then place it in the replace string. See the brackets around the find string and the \1 in the replace string.

HOWEVER: Please note that this will match EVERY line in your document no matter what it is.

In the case of your sample code:

Code:
(^.+$)
Could you put in "replace":
Code:
<p>\1</p>
I would recommend either pasting your text into a blank text file or using Notepad++ or equivalent to do the replacement in the text before pasting it into Sigil. Notepad++ can use the same find/replace strings making easier for me.
d351r3d is offline   Reply With Quote
Old 06-08-2020, 11:40 PM   #8
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 668
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
This site: https://regexr.com/
is really useful for working out regex codes. Has good references, cheatsheets, and a live test. Seems to be compatible with Sigil's version of regex.
AlanHK is offline   Reply With Quote
Reply

Tags
end of line, formatting, regex sigil, text


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Move date from beginning to end of title w/ regex? melba.d Library Management 2 08-04-2018 01:58 AM
Wondering if there is a way to remove end tag with beginning tag LadyKate Editor 5 06-29-2016 04:32 PM
Regex to search at beginning of line kakkalla Sigil 30 06-03-2013 03:08 PM
TOC at the beginning or end? sassanik Writers' Corner 15 08-16-2012 06:08 PM
The beginning of the end for DRM? plib News 111 05-25-2012 09:14 AM


All times are GMT -4. The time now is 07:14 PM.


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