[x3d-public] SFImage regex

Andreas Plesch andreasplesch at gmail.com
Mon Jun 11 07:05:05 PDT 2018


On Mon, Jun 11, 2018 at 9:47 AM Don Brutzman <brutzman at nps.edu> wrote:

> Sounds sensible.  I suspect performance is not impacted whatsoever since
> regex patterns tend to get precompiled... but we'll see.  Getting the
> expressions right is our first priority, optimization (if relevant) can
> follow in the future.
>

Talking about getting them right, I spotted a typo in the SFImage regex. An
extra, leftover }., which allowed '}" as a hex character.

Here is the fixed version:

^\s*(\d|[1-9]\d+)(\s+(\d|[1-9]\d+)){2}(\s+((0x(\d|[a-f]|[A-F]){1,8})|[1-9]\d+|\d))*\s*$

https://regex101.com/r/CJ1h80/6/tests

What actually triggered spotting the typo was this cool regex visualization
service:

https://regexper.com/#%28%28%5Cd%7C%5B1-9%5D%5Cd%2B%29%28%5Cs%2B%28%5Cd%7C%5B1-9%5D%5Cd%2B%29%29%7B2%7D%28%5Cs%2B%28%280x%28%5Ba-f%5D%7C%5BA-F%5D%7C%5Cd%5D%29%7B1%2C8%7D%29%7C%5B1-9%5D%5Cd%2B%7C%5Cd%29%29*%5Cs%29*

-Andreas


>
> On 6/9/2018 10:43 AM, Andreas Plesch wrote:
> > On Sat, Jun 9, 2018 at 1:19 PM, Don Brutzman <brutzman at nps.edu> wrote:
> >> good point... i've been grouping them just to keep the regexes a slight
> bit
> >> more readable, less possibility of error.  we could do cleanup of those
> >> (group) parentheses if it is preferable.
> >
> > The parens do look more readable, at least to the casual regex reader.
> > Parens usually are used for capturing, eg. referencing the matched
> > group later although I am not sure if this is possible with XML
> > regexes which seem more basic. To regex regulars parens therefore may
> > cause human interpreters to look for those references. Also - at least
> > outside of XML - performance may be impacted from using a lot of
> > grouping.
> >
> > Probably best to just leave the parens.
> >
> > Tangentially, repeated ranges also look not so nice but are apparently
> > common: [0-9a-fA-F]
> > [0-9]|[a-f|[A-F] reads better to me and that is why I preferred that.
> > Not sure about any performance implications.
> >
> > -Andreas
> >
> >>
> >> On 6/9/2018 8:45 AM, Andreas Plesch wrote:
> >>>
> >>> On Sat, Jun 9, 2018 at 8:30 AM, Don Brutzman <brutzman at nps.edu> wrote:
> >>>>
> >>>> On 6/8/2018 3:13 PM, Don Brutzman wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>> *  These regexes all assume that leading/trailing whitespace has been
> >>>>> removed. It is possible to prepend/append regex constructs such as
> (\s)+
> >>>>> to
> >>>>> consume outer whitespace.
> >>>>
> >>>>
> >>>>
> >>>> correction: zero or more whitespace characters (\s)* rather than one
> or
> >>>> more
> >>>> whitespace characters (\s)+
> >>>
> >>>
> >>> Yes, but it is not necessary to group the \s class: \s*. I am not sure
> >>> if prepending/appending is preferable to using the collapse whitepace
> >>> XML restriction. Since there are more fluent regex than XML readers,
> >>> it may be.
> >>>
> >>> -Andreas
> >>
> >>
> >>
> >> all the best, Don
> >> --
> >> Don Brutzman  Naval Postgraduate School, Code USW/Br
> brutzman at nps.edu
> >> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>  +1.831.656.2149
> >> X3D graphics, virtual worlds, navy robotics
> http://faculty.nps.edu/brutzman
> >>
> >
> >
> >
>
>
> all the best, Don
> --
> Don Brutzman  Naval Postgraduate School, Code USW/Br
> brutzman at nps.edu
> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> X3D graphics, virtual worlds, navy robotics
> http://faculty.nps.edu/brutzman
>
>

-- 
Andreas Plesch
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180611/6f8447ca/attachment.html>


More information about the x3d-public mailing list