Distill7 Posted June 5, 2019 Share Posted June 5, 2019 I need a way to add a prefix and suffix before every word that has a character style. For example, I want to replace the following text: "The quick brown fox jumps over the lazy dog." to "The quick brown <b>fox</b>jumps over the lazy <b>dog.</b>" I can use the find command to search for the bold text, but I don't know how to add the prefixes and suffixes without deleting the words. Maybe someone can help me using regx. Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted June 5, 2019 Share Posted June 5, 2019 If you tell Publisher to use regular expressions, then you would: Find: (.*) Replace: <b>\1</b> And, of course, you would tell Pubisher to search for text formatted as having a character style of strong. Note: Find/Replace allows you to specify character styles as part of the search, as you know. It's also important to recognize that text which you simply mark Bold (by pressing the B icon) is different from text that has a character style of Strong. You cannot search for text that is merely Bold or Italic. You need to use the character styles. You need to construct the search being aware of the method that you used to make the text appear bold, using either the character style options for the Find or the font-weight option (via the Format entry in the list, as Carl mentioned below). Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
v_kyr Posted June 5, 2019 Share Posted June 5, 2019 Maybe I didn't catched your search/replace problem correctly here, but usually you can do that with normal find and replace procedures ... Search: fox Replace: <b>fox</b> For regex usually something like ... Search: /(fox)|(dog)/g Replace: <b>$&</b> Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2 Link to comment Share on other sites More sharing options...
carl123 Posted June 5, 2019 Share Posted June 5, 2019 16 minutes ago, walt.farrell said: You cannot search for text that is merely Bold or Italic. I think you can By clicking the Cog in the Find panel, selecting Format and then specifying Font Weight = Bold Does this not work for you? walt.farrell 1 Quote To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time. Link to comment Share on other sites More sharing options...
Distill7 Posted June 5, 2019 Author Share Posted June 5, 2019 16 minutes ago, walt.farrell said: If you tell Publisher to use regular expressions, then you would: Find: (.*) Replace: <b>\1</b> And, of course, you would tell Pubisher to search for text formatted as having a character style of strong. Note: Find/Replace allows you to specify character styles as part of the search, as you know. It's also important to recognize that text which you simply mark Bold (by pressing the B icon) is different from text that has a character style of Strong. You cannot search for text that is merely Bold or Italic. You need to use the character styles. Works like a charm, thank you so much. of course I'll have to choose character style:"bold" in the find tab too. 2 11 minutes ago, v_kyr said: Maybe I didn't catched your search/replace problem correctly here, but usually you can do that with normal find and replace procedures ... Search: fox Replace: <b>fox</b> For regex usually something like ... Search: /(fox)|(dog)/g Replace: <b>$&</b> I the find replace to find all of the words that have a certain character style applied to them. I don't have certain words like dog, fox in mind. I just used them as an example. Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted June 5, 2019 Share Posted June 5, 2019 2 minutes ago, carl123 said: I think you can By clicking the Cog in the Find panel, selecting Format and then specifying Font Weight = Bold Does this not work for you? Thank you, Carl. Yes, that works. I did not remember that possibility, and had not dug down into the more general Format item in the list. Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
Distill7 Posted June 5, 2019 Author Share Posted June 5, 2019 I'm having a small problem, the search (.*) along with format:italic seems to pick all kinds of breaks too, like paragraph break, and section breaks. Is there a way to make it find text only and not text markers? Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted June 5, 2019 Share Posted June 5, 2019 3 minutes ago, toutou123 said: I'm having a small problem, the search (.*) along with format:italic seems to pick all kinds of breaks too, like paragraph break, and section breaks. Is there a way to make it find text only and not text markers? Interesting. You could try using (\w*) instead, but that would not match punctuation. Possibly you could try this approach: Put ([^]*) in the Find box. Then put the cursor immediately after the ^ character. Click the magnifying glass under the word Find, and select the Paragraph Break. Do the same for the Frame Break, or any others that are causing you a problem. If you need further help, it would be good if you'd provide a sample .afpub file so we can see exactly what you see Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
Distill7 Posted June 5, 2019 Author Share Posted June 5, 2019 Here is a file for the problem I'm facing, it includes the paragraph breaks inside the prefix-suffix find-replace.afpub is there a way to exclude certain parameters, like (.*) minus paragraph breask? Quote Link to comment Share on other sites More sharing options...
Distill7 Posted June 5, 2019 Author Share Posted June 5, 2019 A quick workaround I found is after you do the intiial find replace, switch to normal mode and do the 2 following tasks find: <b>"paragraph break" replace: "paragraph break"<b> and then find: "paragraph break"</b> replace: </b>"paragraph break" I hope they the ability to save find/replace commands with the official release, it's a bit tiring to type them manually each time. Quote Link to comment Share on other sites More sharing options...
v_kyr Posted June 5, 2019 Share Posted June 5, 2019 You can try a difficult one like this... (?<=\s|^|\b)(?:[-'.%$#&\/]\b|\b[-'.%$#&\/]|[A-Za-z0-9]|\([A-Za-z0-9]+\))+(?=\s|$|\b) which should match words with punctuation but not punctuation alone (see here for general tryouts). - In order to match just alphanumerics use ([A-Za-z0-9]+) instead of (.*). Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2 Link to comment Share on other sites More sharing options...
walt.farrell Posted June 5, 2019 Share Posted June 5, 2019 3 minutes ago, v_kyr said: You can try a difficult one like this... (?<=\s|^|\b)(?:[-'.%$#&\/]\b|\b[-'.%$#&\/]|[A-Za-z0-9]|\([A-Za-z0-9]+\))+(?=\s|$|\b) which should match words with punctuation but not punctuation alone (see here for general tryouts). - In order to match just alphanumerics use ([A-Za-z0-9]+) instead of (.*). Will A-Za-z catch all cases of accented letters? It might be better to use \w I think. Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
Distill7 Posted June 5, 2019 Author Share Posted June 5, 2019 The only problem I faced so far was with paragraph breaks, using (.*) followed by 2 find/replace commands to correct abnormalities works just fine. at least with what I want to do. Quote Link to comment Share on other sites More sharing options...
v_kyr Posted June 5, 2019 Share Posted June 5, 2019 32 minutes ago, walt.farrell said: Will A-Za-z catch all cases of accented letters? It might be better to use \w I think. Didn't tried, since it's more something used for coding and source code, where one usually doesn't use accented letters other than maybe localization languaged UI stuff. So it may work more with plain english etc. Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2 Link to comment Share on other sites More sharing options...
garrettm30 Posted June 5, 2019 Share Posted June 5, 2019 3 hours ago, walt.farrell said: Will A-Za-z catch all cases of accented letters? It might be better to use \w I think. It may be a case for locale aware regular expression. Quote Link to comment Share on other sites More sharing options...
Distill7 Posted June 6, 2019 Author Share Posted June 6, 2019 Another trick I found is to do the following find/replace for normal text Search: paragraph break replace: paragraph braek +format => font weight:normal; italics:off This removes all formatting from pargraph breaks, so they're not included when I add <b>\1</b> to the bold text. walt.farrell 1 Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted June 6, 2019 Share Posted June 6, 2019 7 hours ago, garrettm30 said: It may be a case for locale aware regular expression. Good point. In a locale-aware regex in Publisher [a-zA-Z] also matches the letters with accents and other diacritical marks. Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
fde101 Posted June 6, 2019 Share Posted June 6, 2019 21 hours ago, toutou123 said: I hope they the ability to save find/replace commands with the official release, it's a bit tiring to type them manually each time. If they haven't added this already, with the release coming up in less than 3 weeks, I am somewhat skeptical that this feature will make it into the initial release. I wouldn't be too surprised if it were added in one of the next few point releases, however, and I agree that this would be a helpful feature. Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted June 6, 2019 Share Posted June 6, 2019 1 hour ago, fde101 said: If they haven't added this already, with the release coming up in less than 3 weeks, I am somewhat skeptical that this feature will make it into the initial release. I wouldn't be too surprised if it were added in one of the next few point releases, however, and I agree that this would be a helpful feature. I agree, and I also doubt that function will make the first official release. @toutou123: You might consider having a text file with your commonly used regular expressions saved, so it's only a copy/paste operation rather than retyping. fde101 1 Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 17.7, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.7 Link to comment Share on other sites More sharing options...
garrettm30 Posted June 6, 2019 Share Posted June 6, 2019 I also agree with fde101 and walt.farrell. That they got regular expressions in the first release is amazing, and there is no telling how much time it can save when one knows how to use it. The next step is the ability to save searches. That also can save quite a lot of time, although not on the massive order of regular expressions themselves. I plan to keep a list in a separate file that I will copy and paste. For the moment, it is my opinion that it would be unwise to add any new features this close to release. I suppose they are focusing on just getting it stable and bugs fixed. Once they get 1.7 out the door, I would like us to start the requests for round 2 on find/replace to take it to the next level. Old Bruce 1 Quote Link to comment Share on other sites More sharing options...
dominik Posted June 6, 2019 Share Posted June 6, 2019 1 hour ago, garrettm30 said: I plan to keep a list in a separate file that I will copy and paste. One could save this list as a text snippet in the assets d. walt.farrell 1 Quote Affinity Suite on Windows (V2) and iPad (V2). Beta testing when available. Windows 11 64-bit - Core i7 - 16GB - Intel HD Graphics 4600 & NVIDIA GeForce GTX 960M iPad pro 9.7" + Apple Pencil Link to comment Share on other sites More sharing options...
Distill7 Posted June 7, 2019 Author Share Posted June 7, 2019 11 hours ago, walt.farrell said: I agree, and I also doubt that function will make the first official release. @toutou123: You might consider having a text file with your commonly used regular expressions saved, so it's only a copy/paste operation rather than retyping. I have already done so especially that I didn't master Regx expressions yet. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.