New radio PIDs, more than 8 characters - "solved"

C E Macfarlane c.e.macfarlane at macfh.co.uk
Wed Aug 16 07:42:06 PDT 2017


More on REs ...
--
www.macfh.co.uk/MacFH.html

>     > would we both agree with?:
>     > 	\b[bpw][0-9][a-z0-9]{7,13}\b
>
>     I think it's
>
>         \b[bpw]\d[b-df-hj-np-tv-z\d]{6,13}\b
>
>     to cover the existing ones that are eight long, up to the 15-long
>     w172vg029mkl852 that Vangelis mentioned.  And we may as well
>     borrow from
>     the specification and cut out the vowels rather than allow a-z.

Yes, I agree.

I see that my 7 at the end was an actual error, but for the rest of it
you're saving some characters in capturing the second character, and you're
being more precise in the tail.  I think your suggestion should work well,
and am happy to agree with it.

>     I'd probably put all of it other than the two `\b' into a
>     variable with
>     qr//, and then embed that in regexps as needed, adding `()', or `\b',
>     etc., back.

... where and as needed.  Yes, a sensible approach.

>     Out of interest, I've looked at 3.01's get_iplayer for "]0" to see how
>     it already uses it.
>
>          941         if ( $this->{pid} !~ m{^([pb]0[a-z0-9]{6})$} ) {
>
>     $1 doesn't seem to be used afterwards, so the `()' aren't needed.
>
>         3359         if ( $prog->{pid} =~
>     m{^http.+\/([pb]0[a-z0-9]{6})\/?.*$} ) {
>
>     The `/' are unnecessarily backslashed given that m{} is used
>     so the `/'
>     doesn't have special meaning.  The `.+' means the last thing to match
>     the PID RE is used.  The `/?' makes the terminating slash
>     optional, but
>     this means "http://.../p0abc123def" matches, but $1 ignores the "def".
>     The `.*$' isn't wanted as it's always true.
>
>         4409                 $pid = $1 if $prog->{pid} =~
>     /\/([bp]0[a-z0-9]{6})/
>
>     This time the first PID-like thing would be used.  Again, a
>     "def" would
>     be ignored.
>
>         4416         if ( $pid !~ /^[bp]0[a-z0-9]{6}$/ ) {
>         4521         if ( $pid !~ /^[bp]0[a-z0-9]{6}$/ && $pid !~
>     /^http/ ) {
>         4531                 if ( $pid =~ /^[bp]0[a-z0-9]{6}$/ ) {
>         4603                         if ( $pid =~ /^[bp]0[a-z0-9]{6}$/ ) {
>         4686         } elsif ( $prog->{pid} =~ /^[bp]0[a-z0-9]{6}$/ ) {
>
>     All the same.  Fine.
>
>         5095         if ( $prog->{pid} !~ m{^([pb]0[a-z0-9]{6})$} ) {
>
>     "pb" rather than "bp", just for spice.  No need to capture.
>
>         5253         return $1 if $_[0] =~ m{/?([wpb]0[a-z0-9]{6})};
>
>     This one has a `w'!

I would cry out "Gawdon Bennet!", but he wouldn't hear me from shaking his
head in disbelief.  Even after Martin Clark's post giving a tally of them
all, the full horror of it doesn't really sink in until you see them all
listed together as you have done.  It really is a classic example of the
need to declare a multiply-used value up front at the top of the programme
as a constant or variable, and why this need is the very first item in my
programming check-list!




More information about the get_iplayer mailing list