mercredi 3 septembre 2014

groovy regex grep function not producing expected answer


Vote count:

0




I am attempting to extract the Version tags from a git repo using some regex functions from groovy.



def str = proc.in.text
System.out.println("String: $str")
System.out.println("tokenize: ${str.tokenize()}")
System.out.println("grep: " + ["refs/tags/V0.0.0", "refs/tags/V0.0.1"].grep(~/^refs\/tags\/[vV][0-9]+\.[0-9]+\.[0-9]+$/))
System.out.println("tokenize grep: " + str.tokenize().grep(~/^refs\/tags\/[vV][0-9]+\.[0-9]+\.[0-9]+$/))


And my output is this:



String: SHA1asdf refs/tags/V0.0.0
SHA1fdsa refs/tags/V0.0.0^{}
SHA1hgfd refs/tags/V0.0.l
SHA1dfgh refs/tags/V0.0.l^{}

tokenize: [SHA1asdf, refs/tags/V0.0.0, SHA1asdf, refs/tags/V0.0.0^{}, SHA1hgfd, refs/tags/V0.0.l, SHA1dfgh, refs/tags/V0.0.l^{}]
grep: [refs/tags/V0.0.0, refs/tags/V0.0.1]
tokenize grep: [refs/tags/V0.0.0]


Why isn't the tokenize().grep() producing the expected answer?



asked 40 secs ago







groovy regex grep function not producing expected answer

Aucun commentaire:

Enregistrer un commentaire