Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 11-16-2023, 01:32 PM   #1
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
Why does string (UK) appear twice? (Search&Replace)

Why does UK appear twice?

Search mode: Regular...
Search field: author
Search for: (.*)
Replace with: UK
Destination field: authors
Mode: Append ti field
check - Split result
check - Case sensitive
-------------------------
author before : Juli Zeh
author after: Juli Zeh & UKUK
crnirg is offline   Reply With Quote
Old 11-16-2023, 06:41 PM   #2
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: 31,193
Karma: 136000011
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by crnirg View Post
Why does UK appear twice?

Search mode: Regular...
Search field: author
Search for: (.*)
Replace with: UK
Destination field: authors
Mode: Append ti field
check - Split result
check - Case sensitive
-------------------------
author before : Juli Zeh
author after: Juli Zeh & UKUK
I tried your sample on Regex101.com with Python as the regex variant. See the two screen shots attached. The * matches zero or more characters and returns 2 matches while the + matches 1 or more and returns 1 match.
Attached Thumbnails
Click image for larger version

Name:	regex101_01.png
Views:	24
Size:	62.7 KB
ID:	204742   Click image for larger version

Name:	regex101_02.png
Views:	21
Size:	56.5 KB
ID:	204744  

Last edited by DNSB; 11-16-2023 at 06:43 PM.
DNSB is offline   Reply With Quote
Advert
Old 11-16-2023, 07:52 PM   #3
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,003
Karma: 1312724
Join Date: Aug 2015
Device: Kindle
I remember having a similar problem and filing a bug report about it. Kovid told me it was because of a change of how python3 deals with regex compared to earlier version. Apparently * matches differently than +.

The solution he offered me was to replace .* with .+ and that took care of the problem.

Edit: See the above post by DNSB for explanation of the whey this happens.
capink is offline   Reply With Quote
Old 11-16-2023, 08:39 PM   #4
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
This is the first part of a comment to which I would like to add a second part.

Let's say this is the second part.

After (.+) I get :

This is the first part of a comment to which I would like to add a second part.
Let's say this is the second part. Let's say this is the second part.

For author and title is OK.
Maybe problem is type field Comments ?
Attached Thumbnails
Click image for larger version

Name:	Primer ORIG.jpg
Views:	16
Size:	109.5 KB
ID:	204748  

Last edited by crnirg; 11-16-2023 at 09:04 PM.
crnirg is offline   Reply With Quote
Old 11-16-2023, 08:55 PM   #5
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,003
Karma: 1312724
Join Date: Aug 2015
Device: Kindle
I don't fully understand what is happening there. But I think it has to do with comments being multiline, where each line is being matched separately. Try using the (?s) modifier to turn off single line mode:

Code:
(?s)(.+)

Last edited by capink; 11-16-2023 at 08:58 PM.
capink is offline   Reply With Quote
Advert
Old 11-16-2023, 09:16 PM   #6
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
Yes,yes,yes - super - that's it.

Maybe I'm boring, but let me ask - my second part that adds would actually be the biography of the writer and I would use copy-paste in the field Replace with - could I insert some command at the beginning of the biography so that it is inserted into a new line?
Example:
First part + (some command) Second part (Replace with) and I get:

First part
********
The second part
crnirg is offline   Reply With Quote
Old 11-16-2023, 09:57 PM   #7
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
I fix with (?s)(.+) in Search for and this in Replace with :

*********<div><p>Second part</p></div>


Many thanks for the help.
crnirg is offline   Reply With Quote
Old 11-16-2023, 09:59 PM   #8
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,003
Karma: 1312724
Join Date: Aug 2015
Device: Kindle
Instead of: Mode: Append to field | use: Mode: Replace field

Now use back-referencing to include the original text
Code:
search: (?s)(.+)
replace: \1\nSome random text you want to insert
\1: reference for the matched part i.e (.+)
\n: new line
capink is offline   Reply With Quote
Old 11-16-2023, 10:42 PM   #9
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
Super
Even better - if only I could keep the text format - that would be the top!
crnirg is offline   Reply With Quote
Old 11-17-2023, 02:17 AM   #10
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by crnirg View Post
Super
Even better - if only I could keep the text format - that would be the top!
What are you trying to do with this regular expression? I'm a bit puzzled, and have several guesses but can't advise on the RE without knowing your purpose.
kjdavies is offline   Reply With Quote
Old 11-17-2023, 06:06 AM   #11
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
I have descriptions of a couple of books by the same author - I would like to add information about the author to the end of those descriptions after a while - since I would do it with copy-oaste from the web, it would be convenient to keep the text format for clarity.
I hope I have explained well what I want.
Of course, I also learn a little bit about expressions and their applications.
crnirg is offline   Reply With Quote
Old 11-17-2023, 02:45 PM   #12
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by crnirg View Post
I have descriptions of a couple of books by the same author - I would like to add information about the author to the end of those descriptions after a while - since I would do it with copy-oaste from the web, it would be convenient to keep the text format for clarity.
I hope I have explained well what I want.
Of course, I also learn a little bit about expressions and their applications.
Ah, so if I read this correctly, you want to append a string to the author names.

Steps as I see them:
  • Select books to modify
  • 'Bulk edit'
  • 'Search and Replace' tab
  • Search field: Author
  • Search for: $
  • Replace with: " (UK)"
  • Click 'Apply' (or 'OK', if you're done with the bulk editor)

'$' here means 'end of string', so I am 'replacing the end of the string with a space followed by (UK)'.

This does split the author entries up into multiple. That is, 'Keith Davies' and 'Keith Davies (UK)' are seen as different people, and it'll pick up 'Davies (UK)' as the last name of the second one. They still sort next to each other in the tag browser (which I admit surprised me, as did book details pane showing only 'Keith Davies' and not 'Keith Davies (UK)'). Also, it's important to know that each author in the list will have ' (UK)' appended to their name, not just the list as a whole.

If I wanted to differentiate the editions by nationality, I'd probably put the marker on the title rather than the author. That keeps the books filed under the same author name.

Another option is to use tags, possibly a custom column, for these edition modifiers, then present those next to the title in the book list.
kjdavies is offline   Reply With Quote
Old 11-17-2023, 04:19 PM   #13
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by crnirg View Post
Why does UK appear twice?

Search mode: Regular...
Search field: author
Search for: (.*)
Replace with: UK
Destination field: authors
Mode: Append ti field
check - Split result
check - Case sensitive
-------------------------
author before : Juli Zeh
author after: Juli Zeh & UKUK
I tried with an author with a 'one-word name', one with an author with a 'two-word name', and with an author with a 'three-word name'. In all cases they want to append 'UKUK'.

At a guess, it's returning 'UKUK' because it sees the 'real string' and an 'empty string' (perhaps picking up the start or end of the string as a matching substring). When you have '.+' it can't match the empty string, so you get only a single 'UK'.

Still, when using regex to append or prepend a string to a field like this, I prefer to use the string-start and string-end special characters ('^' and '$' respectively) or to explicitly replace the entire thing, which looks like

Search: ^(.*)$
Replace: \1 UK

The search here says 'replace all characters' -- '(.*)' alone says 'replace any string of 0 or more characters, '^(.*)$' says 'replace the entire string' -- with 'those characters + " UK"'.
kjdavies is offline   Reply With Quote
Old 11-17-2023, 05:00 PM   #14
crnirg
Enthusiast
crnirg began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Nov 2010
Location: Niš, Srbija
Device: Tablet (Android)
Thank you very much for the answers - this was the beginning of my search for a way to add the writer's biography in the comments after the description of the book itself - now with the latest version of the app and Note, a lot of things have been solved - just a few more little things and it will be great.
Thanks again for the replies - learned something.
crnirg is offline   Reply With Quote
Old 11-17-2023, 07:42 PM   #15
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by crnirg View Post
Thank you very much for the answers - this was the beginning of my search for a way to add the writer's biography in the comments after the description of the book itself - now with the latest version of the app and Note, a lot of things have been solved - just a few more little things and it will be great.
Thanks again for the replies - learned something.
Glad to hear it helps. I'm just starting to learn about Notes, wondering if they'll solve some other things for me.
kjdavies is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a search&replace ownedbycats Library Management 3 03-08-2021 05:53 PM
Regex in search problems (NOT Search&Replace; the search bar) lairdb Calibre 3 03-15-2017 08:10 PM
Search & Replace Help paulfiera Conversion 7 08-06-2015 04:52 AM
Search & Replace Scott Nielsen Sigil 4 10-29-2013 01:10 PM
Help with a search & replace mmholt Library Management 11 10-21-2011 07:49 PM


All times are GMT -4. The time now is 05:38 AM.


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