RobC Posted May 21, 2022 Share Posted May 21, 2022 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? Quote Link to comment Share on other sites More sharing options...
Old Bruce Posted May 21, 2022 Share Posted May 21, 2022 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. Quote 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 More sharing options...
RobC Posted May 21, 2022 Author Share Posted May 21, 2022 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 Quote Link to comment Share on other sites More sharing options...
John Rostron Posted May 22, 2022 Share Posted May 22, 2022 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 Quote 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 More sharing options...
walt.farrell Posted May 22, 2022 Share Posted May 22, 2022 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. Quote -- 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 More sharing options...
RobC Posted May 22, 2022 Author Share Posted May 22, 2022 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 Quote Link to comment Share on other sites More sharing options...
RobC Posted May 22, 2022 Author Share Posted May 22, 2022 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 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 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.