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

"Invalid Regular Expression" error while searching for spaces in telephone number


Recommended Posts

I need to find a regular expression to find spaces in a telephone number so I can replace with  non-breaking spaces.

The following GREP works ok on regexr.com to find the two spaces in "Tel: 123 4567"

(?<=Tel:)\x20|(?<=Tel:\x20\d+)\x20

but in Affinity Publisher it says it's an "invalid regular expression" Any ideas what I should substitute?

Link to comment
Share on other sites

I would use 

(Tel:)\s(\d{3})\s(\d)

for find and 

\1nonBreakingSpace\2nonBreakingSpace\3

for replace. With the actual non breaking space from the dropdown list.

Mac Pro (Late 2013) Mac OS 12.7.4 
Affinity Designer 2.4.1 | Affinity Photo 2.4.1 | Affinity Publisher 2.4.1 | Beta versions as they appear.

I have never mastered color management, period, so I cannot help with that.

Link to comment
Share on other sites

Thanks for swift response - that worked for my example but sometimes my phone numbers are a more complicated format and don't follow the same string pattern eg

Tel: +123 4567 45566

Tel: 12348 56612 ext 566

Tel: 12 5667

I tried extending your GREP as 

(Tel:)\s(\S+)\s(\S+)\s(\S+)\s(\S+)

and replaced with \1nonBreakingSpace\2nonBreakingSpace\3nonBreakingSpace\4nonBreakingSpace\5 

but it only worked for the second example with the correct amount of groups

Link to comment
Share on other sites

If you could identify all your non-breaking spaces in context, then you use alternates such as:

(Tel:)\s(\d)|(\d)\s(\d)|(\d)\s(ext)|(ext)\s(\d) etc

You may need to apply the GREP two or more times. Or does APu include a Global option to the GREP?

John

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

1 hour ago, John Rostron said:

Or does APu include a Global option to the GREP?

I'm not sure what you mean by "Global" in this context, John. Sorry.

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

9 hours ago, John Rostron said:

If you could identify all your non-breaking spaces in context, then you use alternates such as:

(Tel:)\s(\d)|(\d)\s(\d)|(\d)\s(ext)|(ext)\s(\d) etc

You may need to apply the GREP two or more times. Or does APu include a Global option to the GREP?

John

Thanks, John

When I try this it picks up some of the digits as well - I think I'm going to go with the following two GREPs and just keep an eye for the exceptions

(?<=Tel:)\s 

(?<=\d)\s(?=\d)

Rob

Link to comment
Share on other sites

1 hour ago, anto said:

I tried to create extensions, it works partially.

You can try it.

(Tel:)()|(\d{1,})|(Tel:)((\s\+|\s|\+))(\d{1,})(\s)(\d{1,})|(\s)(\d{1,})

Replace by $1$3$11-

where "-" non-breaking space

rege2.JPG.91eee1532631d75bab6cfef9d4e88ce4.JPG

 

Hi anto

this works really well for me so your time is greatly appreciated - I'll make sure I spend some time trying to understand the how it works

Rob

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.