﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
24095	Unexpected MapCSS REGEX errors	goodidea	team	"I'm currently working on a more complex custom MapCSS (for traffic signs – but that's not relevant here), that makes extensive use of selectors with REGEX (regular expressions).

But some REGEX expressions did not work – and there were error messages in the JAVA console that I couldn't explain at all. And I had previously tested the REGEX expressions extensively, e.g. on https://regex101.com/, where you can also set JAVA as a REGEX flavor, and they seemed to be valid and error-free. I also got the desired results with test strings.

And according to the JOSM documentation (see https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#Conditionselector) the REGEX flavor, which is supported by JOSM, is the one of JAVA 11 – at least that's what the documentation says (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html#sum).

After a lot of testing, I found out that this is probably the case, but that some special characters and predefined character classes etc. cause an error in JOSM, namely these (and I especially wanted to use \h for whitespace characters – which I have now replaced with \s, which works in contrast to \h – see below):

{{{
\t
\n
\r
\R
\f
\a
\e
\h
\H
\v
\V
\Q
\E
}}}


If you use this in a MapCSS, you will get an error message like this in the JAVA Console:

{{{
2025-01-23 19:27:56.578 SEVERE: Skipping to the next rule, because of an error: org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException: Encountered "" ""~"" ""~ """" at line 137, column 19.
Was expecting one of:
    ""set"" ...
    <IDENT> ...
    <UINT> ...
    <STRING> ...
    ""("" ...
    <UFLOAT> ...
    <HEXCOLOR> ...
    <S> ...
    ""="" ...
    ""!"" ...
    ""+"" ...
    ""-"" ...
    ""/*"" ...
    <S> ...
    ""-"" ...
    <UINT> ...
    ""-"" ...
    <UFLOAT> ...
    <UINT> ...
    <IDENT> ...
    ""set"" ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <IDENT> ...
    ""set"" ...
}}}
 
These special characters, predefined character classes and boundary matchers, however, work without problems:

{{{
\d
\D
\s
\S
\w
\W
\b
\B
\A
\G
\z
\Z
}}}

Is this a bug in the MapCSS parser – or is the documentation of which REGEX expressions are supported “just” inadequate and should be clarified?

==== What steps will reproduce the problem?
Create a custom CSS with a rule like:

{{{
node[traffic_sign=~/^xxx\hxxx.*/] {
   text: auto;
}
}}}

... and add it to the JOSM map paint styles.


==== Additional system information:

Revision:19277
Build-Date:2025-01-04 02:30:34
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (19277 en) Mac OS X 10.14.6
OS Build number: Mac OS X 10.14.6 (18G9323)
Memory Usage: 998 MB / 4096 MB (453 MB allocated, but free)
Java version: 17.0.13+11-LTS, Azul Systems, Inc., OpenJDK 64-Bit Server VM
Look and Feel: com.apple.laf.AquaLookAndFeel

Last errors/warnings:
- 03265.734 E: Skipping to the next rule, because of an error: org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException: Encountered "" ""~"" ""~ """" at line 137, column 19.
"	defect	closed	normal	25.01	Core		fixed		
