Groovy syntax for regular expression matching

前端 未结 3 1082
终归单人心
终归单人心 2020-12-24 01:07

What is the Groovy equivalent of the following Perl code?

my $txt = \"abc : groovy : def\";
if ($txt =~ / : (.+?) : /) {
  my $match = $1;
  print \"MATCH=$m         


        
3条回答
  •  离开以前
    2020-12-24 01:38

    This is my best understanding of how to do this using Groovy syntax (but see lfaraone's response too):

    import java.util.regex.Matcher
    
    def txt = 'abc : groovy : def'
    if (txt =~ ~/ : (.+?) : /) {
        def match = Matcher.lastMatcher[0][1]
        println "MATCH=$match"
    }
    

提交回复
热议问题