Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 6553)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 6554)
@@ -22,9 +22,11 @@
     abstract public boolean applies(Environment e);
 
-    public static Condition create(String k, String v, Op op, Context context) {
+    public static Condition create(String k, String v, Op op, Context context, boolean considerValAsKey) {
         switch (context) {
         case PRIMITIVE:
-            return new KeyValueCondition(k, v, op);
+            return new KeyValueCondition(k, v, op, considerValAsKey);
         case LINK:
+            if (considerValAsKey)
+                throw new MapCSSException("''considerValAsKey'' not supported in LINK context");
             if ("role".equalsIgnoreCase(k))
                 return new RoleCondition(v, op);
@@ -144,4 +146,5 @@
         public final String v;
         public final Op op;
+        public boolean considerValAsKey;
 
         /**
@@ -151,14 +154,16 @@
          * @param v the value
          * @param op the operation
+         * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
          */
-        public KeyValueCondition(String k, String v, Op op) {
+        public KeyValueCondition(String k, String v, Op op, boolean considerValAsKey) {
             this.k = k;
             this.v = v;
             this.op = op;
+            this.considerValAsKey = considerValAsKey;
         }
 
         @Override
         public boolean applies(Environment env) {
-            return op.eval(env.osm.get(k), v);
+            return op.eval(env.osm.get(k), considerValAsKey ? env.osm.get(v) : v);
         }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 6553)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 6554)
@@ -367,13 +367,18 @@
     int i;
     Condition.Op op;
+    boolean considerValAsKey = false;
 }
 {
     key=tag_key() s()
     (
-        LOOKAHEAD(2)
-            <EQUAL> <TILDE> { op=Condition.Op.REGEX; } s() val=regex()
-        |
-        LOOKAHEAD(2)
-            <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; } s() val=regex()
+        LOOKAHEAD(3)
+            (
+                    <EQUAL> <TILDE> { op=Condition.Op.REGEX; }
+                |
+                    <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; }
+            )
+            s()
+            ( <STAR> { considerValAsKey=true; } )?
+            val=regex()
         |
             (
@@ -391,4 +396,5 @@
             )
             s()
+            ( <STAR> { considerValAsKey=true; } )?
             ( 
                 LOOKAHEAD(2) 
@@ -412,5 +418,5 @@
             f=float_() { val=Float.toString(f); }
     )
-    { return Condition.create(key, val, op, context); }
+    { return Condition.create(key, val, op, context, considerValAsKey); }
 }
 
Index: /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy	(revision 6553)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy	(revision 6554)
@@ -106,3 +106,22 @@
         assert !c1.applies(getEnvironment("lanes:foobar", "3"))
     }
+
+    @Test
+    public void testKeyKeyCondition() throws Exception {
+        def c1 = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[foo = *bar]")).condition(Condition.Context.PRIMITIVE)
+        def w1 = new Way()
+        w1.put("foo", "123")
+        w1.put("bar", "456")
+        assert !c1.applies(new Environment().withPrimitive(w1))
+        w1.put("bar", "123")
+        assert c1.applies(new Environment().withPrimitive(w1))
+        def c2 = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[foo =~ */bar/]")).condition(Condition.Context.PRIMITIVE)
+        def w2 = new Way(w1)
+        w2.put("bar", "[0-9]{3}")
+        assert c2.applies(new Environment().withPrimitive(w2))
+        w2.put("bar", "[0-9]")
+        assert c2.applies(new Environment().withPrimitive(w2))
+        w2.put("bar", "^[0-9]\$")
+        assert !c2.applies(new Environment().withPrimitive(w2))
+    }
 }
