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

Regex replacement matching not working


Recommended Posts

The app finds my character-styled spans correctly but ignores \&   $&   $MATCH  and so forth. It inserts them as literals instead of replacing with the entire match. Yes, I selected regex in the Find dropdown.

Windows 11. v2.04

Link to comment
Share on other sites

Publisher uses the Boost reg-ex library. You can find the full reference at the Boost.org site, or try regular-expression.info and select Boost as the variant for the syntax descriptions. 

\& is not Boost syntax for what you're trying to do. You might try \0 or $0. (I'm away from my computer and can't check right now.) 

 

-- 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.1.2, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.1.2

Link to comment
Share on other sites

0 syntax didn't work.

From the help file -- "Affinity Publisher supports Perl and ECMAScript (with perl extensions) expressions. Regular expressions use the "C" or "POSIX" locale, while Locale Aware Regular Expressions use the locale inferred from the text being searched and locale aware collation is implied."

I am a programmer and familiar with using regex. Used it successful in afpub 1.x. 

Followed syntax on "including www.regular-expressions.info and regexone.com."

Link to comment
Share on other sites

  • Staff

Hi Ed Lyons,

Please could you provide a sample document demonstrating this issue? Just to clarify this REGEX worked correctly in V1 but not in V2?

Thanks
C

Please tag me using @ in your reply so I can be sure to respond ASAP.

Link to comment
Share on other sites

My particular file started in 2.0. I was referring to similar regex operations in 1.0. 

You can verify the issue with the following steps.

Start a new file. Paste a bunch of text. Format random spans with a character style, e.g. strong. Check regular expressions in Find dropdown and search for Strong. All of them appear in the results list. Now try to bracket each occurrence with [\&] or [$&] or [$0]. Fail.

Link to comment
Share on other sites

On 2/21/2023 at 12:39 PM, Ed Lyons said:

Start a new file. Paste a bunch of text. Format random spans with a character style, e.g. strong. Check regular expressions in Find dropdown and search for Strong. All of them appear in the results list. Now try to bracket each occurrence with [\&] or [$&] or [$0]. Fail.

What search string did you use? If you supply only a character style, and no actual regular expression, then I don't think there's a group for the referback (\&, $&, $0) to refer to.

But having said that, there are errors in doing find/replace using .* as the search string, and I can't get any replaces to work in V1 (1.10.6) if I use .* and specify a character style. The Find works properly, but no Replaces work for me (even trying to replace with a fixed string like aaa for example).

This seems to be true in 2.1.0.1709 Beta, too.

Switching the Search string to \w* allows the Find to work, and then a replacement with [$0] or [$&] works, in both V1 and in 2.1 Beta.

Using \& in the Replace field, though, just gives a literal & which I think is correct for Boost RegEx processing, with the options that I think Publisher is using.

 

-- 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.1.2, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.1.2

Link to comment
Share on other sites

Match All should not need a referback?!!

I tried both .* and only a character style and like you did not achieve success.

You keep referring to Boost. Researching that, I see it claims Perl support, which makes sense with the help file statement. I am mentioning this because if Boost provides more or less support then maybe the help file needs to be updated to reflect that with better syntax sources?

Your \w* workaround is giving me weird results, ie. duplicate replacement strings before and after and in between. It's trying hard!!  :) 

Link to comment
Share on other sites

3 minutes ago, Ed Lyons said:

Your \w* workaround is giving me weird results, ie. duplicate replacement strings before and after and in between.

I'm not seeing that, and would need more details.

-- 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.1.2, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.1.2

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.