RobC Posted May 21, 2022 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
Old Bruce Posted May 21, 2022 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.6 Affinity Designer 2.6.0 | Affinity Photo 2.6.0 | Affinity Publisher 2.6.0 | Beta versions as they appear. I have never mastered color management, period, so I cannot help with that.
RobC Posted May 21, 2022 Author 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
John Rostron Posted May 22, 2022 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 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
walt.farrell Posted May 22, 2022 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 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. Laptop 2: Windows 11 Pro 24H2, 16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU iPad: iPad Pro M1, 12.9": iPadOS 18.5, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sequoia 15.5
RobC Posted May 22, 2022 Author 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
RobC Posted May 22, 2022 Author 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
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.