![]() |
#1 |
Enthusiast
![]() 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 |
![]() |
![]() |
![]() |
#2 | |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
Last edited by DNSB; 11-16-2023 at 06:43 PM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() 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 ? Last edited by crnirg; 11-16-2023 at 09:04 PM. |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Enthusiast
![]() 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 |
![]() |
![]() |
![]() |
#7 |
Enthusiast
![]() 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. |
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 \n: new line |
![]() |
![]() |
![]() |
#9 |
Enthusiast
![]() 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! |
![]() |
![]() |
![]() |
#10 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
|
![]() |
![]() |
![]() |
#11 |
Enthusiast
![]() 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. |
![]() |
![]() |
![]() |
#12 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
Quote:
Steps as I see them:
'$' 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. |
|
![]() |
![]() |
![]() |
#13 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
Quote:
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"'. |
|
![]() |
![]() |
![]() |
#14 |
Enthusiast
![]() 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. |
![]() |
![]() |
![]() |
#15 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
Quote:
|
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
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 |