Find using Regular expressions
The documentation for e.g. [font=”Courier New”]matrices.find(param)[/font] says that the parameter can be a regular expression – very convenient if you’re looking to do a partial match on a name. However I can’t make this work.
For example
[code:1gylbusm]matrices.each{if (it.name =~ /foo/ ) x << it }[/code:1gylbusm] will return a matrix with a name that includes “foo”,
but
[code:1gylbusm]x = matrices.find(/foo/)[/code:1gylbusm] doesn’t return anything
Ben,
It seems the issue is that the matching is done on the full string. So to match a matrix named “foo bar” you need to use: [font=”Courier New”] matrices.find(/foo.*/)[/font]
This is equivalent to the Groovy operator [font=”Courier New”] ==~ [/font]
I would suggest it would be more natural to use the equivalent of [font=”Courier New”] =~ [/font] which finds matches [b:3hz6esdy]within [/b:3hz6esdy]a string. That would enable [font=”Courier New”] matrices.find(/foo/)[/font] to return the matrix “foobar”, not only the matrix “foo”.
But at least I’ve found something that works for now…
Thanks
Simon