Jump to content

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

MacBook Pro (13-inch, Mid 2012) Mac OS 10.12.6 || Mac Pro (Late 2013) Mac OS 11.7

Affinity Designer 1.10.5 | Affinity Photo 1.10.5 | Affinity Publisher 1.10.5 | 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

   Desktop: new:  Windows 11 Home, version 21H2 (22000.613) 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090  (old: 16GB memory, Intel Core i7-6700K @ 4.00GHz, GeForce GTX 970 )
   Laptop:  Windows 10 Home, version 21H2 (19044.1706) 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
    Affinity Photo 1.10.5 (.1342) and 1.10.5.1342 Beta   / Affinity Designer 1.10.5 (.1342) and 1.10.5.1342 Beta  / Affinity Publisher 1.10.5 (.1342) and 1.10.5.1282 Beta
 iPad Pro M1, 12.9", iPadOS 15.6.1, Apple Pencil 2, Magic Keyboard

  Affinity Photo 1.10.5 (.280) and 1.10.2 (.266) Beta / Affinity Designer 1.10.5 (.21) and 1.10.3 (.19) Beta 

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

I tried to create expression, 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

 

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

×
×
  • Create New...

Important Information

Please note there is currently a delay in replying to some post. See pinned thread in the Questions forum. These are the Terms of Use you will be asked to agree to if you join the forum. | 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.