#2582 Regex Examples

jhughes Fri 9 Dec 2016

Been trying to figure out how to do a simple split on a string match but looks like Regex is the only way to do this as it's not part of a the Str class. Can't seem to figure out the syntax of that and no examples on using the Regex seem to be available. Can somebody provide me with some basic examples using the Regex? Mainly I want to be able to replicate Java string.split(String regex) method.

SlimerDude Fri 9 Dec 2016

Java's String.split() methods calls Pattern.split()

Fantom's Regex.split() method also calls Pattern.split() so taking Java's example, you should be able to use it like this:

":".toRegex.split("boo:and:foo") // --> [boo, and, foo]
"o".toRegex.split("boo:and:foo") // --> [b, , :and:f]

If you just want to try out some Fantom regex's then you can use the Fantex Website; it's a handy utility to test regular expression groupings and see generated Fantom code

Login or Signup to reply.