Skip to content

Instantly share code, notes, and snippets.

@mykelalvis
Last active June 18, 2019 22:27
Show Gist options
  • Save mykelalvis/7e22e74a67f714999d3ea07063d053f0 to your computer and use it in GitHub Desktop.
Save mykelalvis/7e22e74a67f714999d3ea07063d053f0 to your computer and use it in GitHub Desktop.
RegexSucksInAllLanguages
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