Thursday, March 31, 2011

vCO - use and examples of RegExp (regular expression) Update

I just learned a little bit more about RexExP in vCO. The problem and solution track could found at (there is no bug in RexExp, only a poor description of the method in vCO). A basic usage was already published in this previous post.

The string.match() is used to find substrings matching a pattern, the RegExp. But when you call this expecting a multiple return, you'll only get the first match.

test = "Cats don't eat catfish. Not my cat";
System.log (test.match("cat"));

will return only one element in array: "cat" - the first match found in catfish.

By expanding the RegExp with modifiers you will receive all results (maybe you know them from JavaScript).

test = "Cats don't eat catfish. Not my cat";
System.log (test.match(new RegEx("cat", "g")));

returns "cat,"cat" for both cat in string.
Using "i" will return "Cat".
And the combination gi "Cat", "cat", "cat"
  • i for case independend search
  • g for global search
  • gi as combination of both

This is the expected behavior mentioned in all tutorials.

Regards, Andreas

No comments:

Post a Comment