These questions are still within the framework of Apple Shortcuts
UK Road number designations (as far as I’m aware) are a single letter, A, B, C, D, M followed by a 1, 2, 3 digit number. I want the regex to recognise that pattern so I can do a replace (actually a remove) on it.
I have a UK country field that on occasion gets populated with a UK post code. This is a data error. To get round the issue I want to ‘null’ the field. The easiest way is to say if there is a numeric from 0 to 9 in that field take action and set it to null.
The problem is that in an apple shortcut, I can only do a ‘contains’ operation. The way round it would be to replace any number in the field with a ‘$$$.’ Then use ‘contains’ to check if the ‘$$$.’ marker exists in the field, if it does then set the field to null. So here I’m looking for the regex to detect a numeric characfer and replace it with the marker?
Can anyone assist? I don’t want to bother @peavine with these questions as he must be tired of me asking such questions
I wish I could get my head around regex but it is way beyond me.
The UK’s A roads can have 1 - 4 digits in their numbers. Additionally, some have “(M)” suffixes to indicate that motorway rules apply on those sections.
B road numbers have 3 or 4 digits.
Motorway (“M” prefix) numbers have 1 - 3 digits. Additionally, there’s an alternative route to the M6 called the “M6 Toll”, which may be stylised as “M6toll”.
Other prefixes exist locally and for cycleways, according to Wikipedia, but I don’t recall ever having seen any and their use on signs is apparently “not advised” in England.
A regex pattern to match these would depend on how likely the target string is to contain a sequence that could be mistaken for a road number or simply how finicky you want to be. Ignoring the possibility of mistaken identity, this would do the trick:
Using [ABCDHMUQV]\d{1,4}(?:(M)| ?[Tt]oll)? is working well with the roads. Can it be adjusted though so that it can remove:
A345 - Roads as it is now
, A345 - Trailing comma and space (from the previous part of the string) then the Road
A345 - Trailing SPACE after the road name
Again I can do these with multiple passes but I thought I’d ask as it would make it easier to work with.
Thanks as always.
You should work on your RegEx further.
Everything in M/Toll stuff is all optional and is always matching. You’ll also notice full empty line space / Line Feed being captured. This is the optional match always matching.
Work on line anchors or further conditionals.
I would capture the stuff you wanna keep in group and use that in replacement