The usage of .* has never been a required feature for Vassal property
syntax, unless you are using the 3.2 trunk and it has stuff incorporated
that might require syntax change from what is used now (Cant say as I do not
know how that is going to work - haven’t messed with it)
The right hand side of !~ is a regular expression. Does $BasicName$ evaluate to a regular expression? Highly unlikely unless you have very weirdly named counters. Hence the need for you to the ‘.*’ to force $BasicName$ to be a regular expression that matches your locations.
Perhaps this is the problem - what do you mean does it evaluate to a regular expression? The documentation is very sparse on this, and I have only been able to find 3 or 4 posts discussing the use of regexes in the forums. I have a lot of experience using regexes with Perl and grep, but it is always a question of syntax.
Here is the behavior I expext:
DB<4> print “true” if “GlutEyeForebostinator” !~ /Head/
==>true
DB<5> print “true” if “GlutEyeForebostinator” !~ /Glut/
==>false
DB<6> print “true” if “GlutEyeForebostinator” !~ /Eye/
==>false
SplopLocations is a concatenation of 3 counter names - I simply want to match every counter name against the concatenation to see if it doesn’t match…
Is my problem a syntax problem?
Am I not understanding some fundamental difference with Java regexes? From reading the JDK javadocs, they seem 100% compatible when programming in Java - but this isn’t Java, this is VASSAL…
Once I figure this out, I’m happy to contribute a documentation patch.
I no nothing about Perl, but /Head/ and /Glut/ are not regular expressions as such and will not match anything but themselves. The Perl !~ operator must be implying some additional behaviour.
If SplopLocations was set to ‘Glut|Eye|Forebostinator’, then
BasicName!~$SplopLocations$ would do what you want.
Thanks for taking the time to look into this and help make it more clear.
This is not true to my experience. Perhaps I’m not clear.
Perl (and grep) use the forward slash to delimit the regex. So /Glut/ is a fine, but simple, regexp.
Any string is a regular expression - and it will match any string that contains it. For example:
“Glut” =~ Glut ==> true
Like you said - not so useful - I could just use ‘=’ for such a simple case, but this is also true:
“HeadGlutEye” =~ Glut ==> true
And this is what I’m trying to do, or more to the point this:
“HeadGlutEye” !~ Foot ==> true
I want to see that the location Foot is not in the string.
Now this is also true, but it should not be necessary:
“HeadGlutEye” !~.Foot. ==> true
The extra matching all characters at the front and back of the string are totally pointless. Right now, this is required in VASSAL to get things working - so I think something is broken.
None, it is just the analogous operator of != for regexes, just as it seems it is being used in VASSAL - but again there is nothing about it in the documentation - so I could be horribly wrong - I’m using it just like the perl operator.
Yes, that would work, too - but trying to use VASSAL to build up the string ‘Glut|Eye|Forebostinator’ is much harder than simply concatenating them all together and doing the opposite match. In Java, I’d just have a list, and then join each element with a ‘|’… nice and dandy… I haven’t worked out how to do that with VASSAL yet.
More to the point, what I’m trying should work. Again, unless I am fundamentally missing something about how VASSAL is implementing regexes. So I hope to figure out either what hole there is in my understanding, or help identify a potential bug.
That is completely other than how I would expect this to work.
One problem is that we’re missing some necessary delimiters around the
pattern:
SplopLocations !~ /$BasicName$/
Those slashses need to be there, otherwise there’s no way to tell the
difference between $BasicName$ and $BasicName$ with whitespace on either
side of it.
The primary problem I see, however, is that $BasicName$ and .$BasicName$.
as a one-off match pattern should be equivalent. If $BasicName$ contains the
string ‘foo’, then both should match exactly the strings which contain ‘foo’
as a substring. If they don’t, that’s broken.
In the longer term, the current ‘Property Expressions’ need to be replaced by a BeanShell implementation, where Regexp’s will be handled by a function. You’ll do something like
My use of regexes comes from the perspective of a Unix sysadmin - you are always asking the find() question… I know a word or a phrase, and I want to know all lines that contain that word or phrase someplace…
This Pattern.matches() concept of the JDK is a new one for me.
Yes - that would work. I chose not to do it that way because I need to construct the string at the beginning of the game when the player hides three pieces in different locations. It was much simpler with VASSAL to just concatenate all the locations together into a single string - without the ‘|’ separator. I’m still learning the tricks of VASSAL…
I would like to store the names in a list and when the player makes a check I’d search each member of the list… But since I don’t have lists - I figured I’d use a string and do a regex search.
I know how to get the string: |Head|Glut|Eye - but I havent figured out how to remove that first ‘|’ character…
Sorry, I’m not sure what you’re asking - could you say it differently?
I’ve only ever used Regexps from the other perspective - is the String S described by the regexp R or not? This is really the sense in which the regexps are used in Property Match Expressions. You and Joel are a special subclass of users that leads you to expect certain behaviour from the ‘=~’ and ‘!~’ because they happen to look the same as the Perl operators. The Perl form of behaviour is not necessarily what we need. However, my past experience of trying to change the minds of *nix people leads me to pull completely out of this conversation as this point and leave it to Joel to sort out I am not sure what effect the changes might have on existing modules.
Your scheme will fall apart if the search expressions is Foot and the options included FootSore and Footloose, it is not a general purpose solution.