Reputation: 2606
l'm new to Regex. Currently I'm trying to get all consequences of symbols without spaces from a string and to get null when they end.
var pattern:Regex=new Regex("[^ ]+");
var s:String;
for(var i:int=0;i<10;++i)//10 is for debugging because otherwise it will never end
{
s=pattern.Match("speed movement_vector Rigidbody walk_mode").Value;
if(!s)
break;
Debug.Log(s);
}
This finds only 'speed'.
In this article I've found G command which finds occurrence exactly after the last match, i.e. it cannot skip spacebar.
Besides, I don't understand it, because my pattern
var pattern:Regex=new Regex("\G\[^ ]+");
only throws errors about "Unexpected character G".
Upvotes: 1
Views: 101
Reputation: 11132
The reason for this is because \
is an escape character in both unityscript and regex. To fix this, add another \
before the first one (the second one should be unnecessary):
var pattern:Regex=new Regex("\\G[^ ]+");
Upvotes: 1