On 2021-11-08 08:07PM, codesoap@mailbox.org wrote:
> Hi all,
> > =>[<whitespace>]<URL>[<whitespace><USER-FRIENDLY LINK NAME>]
> From this description I don't know whether <USER-FRIENDLY LINK NAME>
> MAY be empty. Which of these regular expressions would be correct to
> parse a link line?
The user friendly link name is optional, however if it is present
then the whitespace after the url is mandatory as well. In other words,
the URL is mandatory, and you either have no link name and no space
after the URL or a link name and mandatory space(s) after the URL.
So you have the following possibilities for link lines:
=>url <- no link name, no space between => and url
=> url <- no link name, one or more spaces separating
=>url name <- link name present, no space between => and url
=> url name <- link name present, one or more spaces separating
> a) ^=>[ \t]*([^ \t]+)(?:$|[ \t]+([^ \t].*)$)
> b) ^=>[ \t]*([^ \t]+)(?:$|[ \t]+([^ \t]?.*?)$)
I believe the latter (option b) would be correct. I would remove the
final "[^ \t]?" and simplify it down to this:
^=>[ \t]*([^ \t]+)(?:$|[ \t]+(.*)$)
You don't really need regex though, just skip past the =>[whitespace],
then the url is splitting on the first space and the remainder is
everything else.
~nytpu
--
Alex // nytpu
alex@nytpu.com
gpg --locate-external-key
alex@nytpu.com