[x3d-public] SFImage regex

Andreas Plesch andreasplesch at gmail.com
Fri Jun 8 11:36:07 PDT 2018


On Fri, Jun 8, 2018 at 2:19 AM Don Brutzman <brutzman at nps.edu> wrote:

> i tried testing this against PixelTexture value
>
>         2 4 3 0xff0000 0xffff00 0x007700 0xff0077 0x0000ff 0xff7700
> 0x00ff77 0x888888
>
> from scene
>
>
> http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter05AppearanceMaterialTextures/PixelTexture.x3d
>
> using https://regex101.com and that tests satisfactorily.
>
> however the default value of '0 0 0' fails according to XML Spy, so there
> is still a problem here...
>

I could confirm that this is due to XML regex expressions not considering
anchors, in particular the $ end of string anchor.

Without anchors the regex becomes longer and a bit more complicated, still
not allowing leading zeroes or commas:

^\s*(\d|[1-9]\d+)(\s+(\d|[1-9]\d+)){2}(\s+((0x([a-f]|[A-F}|\d]){1,8})|[1-9]\d+|\d))*\s*$
(allowing for leading and trailing white space, and anchoring)

(\d|[1-9]\d+)(\s+(\d|[1-9]\d+)){2}(\s+((0x([a-f]|[A-F}|\d]){1,8})|[1-9]\d+|\d))*
(untested XML version which is implicitly anchored, assuming the whitespace
collapsing restriction)

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

lets everybody test and improve this regex with some of the more
challenging cases as unit tests, including the default 0 0 0 case.

It is more important to come up with examples which almost match but
actually should not match than testing conforming examples such as the
web3d example library. Of course there should not be any false positives,
eg. not matching examples which are in fact fine.

The new regex had to split the matching of the 3 initial integers into two
parts. First matching the first integer, then matching at least one
whitespace followed by an integer, twice.
For optional value matching, the order is now at least one whitespace
followed by a number rather than number then whitespace, to avoid requiring
whitespace at the very end. This in turn required an ordering of the or
number branches to hex, then multidigits, then single digits for reasons I
hesitate to fully explore but probably having to do with greediness.
The new regex also uses the \d and \s classes for conciseness, as well as
Leonards idea to limit hex values to at most 8 characters.

TODO: clarify commas, spec. says commas in SF fields are whitespace, so
should be allowed. But allowing in SF fields and then not allowing them in
the corresponding MF field for other than set separation is quite confusing.

Give it a spin, -Andreas


> in any case, great start! have added it to X3D v4.0 schema for further
> experimentation, in this case under the annotations until working better.
>
> deployed online.  however can't get svn to work here so checkins will be
> another time.
>
>
> http://www.web3d.org/specifications/X3dSchemaDocumentation4.0/x3d-4.0_SFImage.html
>
>
> On 6/7/2018 11:11 AM, Andreas Plesch wrote:
> > Ok, let's give it a try:
> >
> > [ \t]*(([0-9]|[1-9][0-9]+)([
> ]+|$)){3}(([0-9]|([1-9][0-9]+)|(0x([0-9]|[a-f]|[A-F])+))([ ]+|$))*
> >
> > In words:
> >
> > match any leading white space followed by
> > exactly three times the following
> >   - one of the following
> >     - either a single digit (including 0) or
> >     - a two or more digit number starting with a 1 to 9 digit
> >   - followed by either
> >    - one or more spaces
> >    - or the end of the string (accommodating the default '0 0 0' case)
> > then optionally followed zero or more times by
> >    - one of the following
> >      - either a single digit (including 0) or
> >      - a two or more digit number starting with a 1 to 9 digit
> >      - 0x followed by at least one of
> >         - a single digit or
> >         - a to f letter or
> >         - A to F letter
> >    - followed by either
> >      - one or more spaces
> >      - or the end of the string
>
>
> 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/20180608/0cc4683d/attachment.html>


More information about the x3d-public mailing list