Last active
June 18, 2019 22:27
-
-
Save mykelalvis/7e22e74a67f714999d3ea07063d053f0 to your computer and use it in GitHub Desktop.
RegexSucksInAllLanguages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher | |
//@Grapes([ | |
// @Grab(group='org.codehaus.groovy', module='groovy-ant', version='2.5.7') | |
// ]) | |
def ant = new AntBuilder() | |
def scanner = ant.fileScanner { | |
// fileset(dir:"${project.build.directory}") { | |
fileset(dir:"/home/mykel.alvis/git/nccirefdatapackager/target/dl") { | |
include(name:"**/*.txt") | |
} | |
} | |
def found = false | |
for (f in scanner) { | |
println("Found file $f") | |
def matchLine = /^(\w+)\t([*]?)\t(\w+)\t([\w*]+)\t([\w\*]+)\t(\d+)\t(.*)$/ | |
f.eachLine { String line -> | |
if (line.startsWith("001")) | |
println "Stopping" | |
if (!(line ==~ matchLine )) { | |
println "No match for -> '$line'" | |
} else { | |
def group = ( line =~ matchLine ) | |
if (group.find()) { | |
def size = group.size() | |
// println "$size $line " | |
if (group.size() < 1) | |
println ("Line ${line} does not match") | |
else { | |
def m1 = group[0][3] | |
println "Group0 -> $m1 " | |
// group.groups.each { g -> | |
// println "$g" | |
// } | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment