Jump to content
You must now use your email address to sign in [click for more info] ×

How to add suffix and prefix in find and replace


Recommended Posts

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.

 

Link to comment
Share on other sites

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).

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

Maybe I didn't catched your search/replace problem correctly here, but usually you can do that with normal find and replace procedures ...

  1. Search: fox
  2. Replace: <b>fox</b>

For regex usually something like ...

  1. Search:   /(fox)|(dog)/g
  2. Replace:  <b>$&</b>

☛ 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

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?

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

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 ...

  1. Search: fox
  2. Replace: <b>fox</b>

For regex usually something like ...

  1. Search:   /(fox)|(dog)/g
  2. 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.

Link to comment
Share on other sites

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.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

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:

  1. Put ([^]*) in the Find box. Then put the cursor immediately after the ^ character.
  2. Click the magnifying glass under the word Find, and select the Paragraph Break.
  3. 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 :)

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 (.*).

☛ 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

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.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

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.

☛ 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

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.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Affinity Designer 1 & 2   |   Affinity Photo 1 & 2   |   Affinity Publisher 1 & 2
Affinity Designer 2 for iPad   |   Affinity Photo 2 for iPad   |   Affinity Publisher 2 for iPad

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

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.