Skip to content
14paxton edited this page Aug 6, 2023 · 3 revisions

title: RegEx permalink: GroovyNotes/RegEx category: GroovyNotes parent: GroovyNotes layout: default has_children: false share: true shortRepo:

  • groovynotes
  • default


Table of contents {: .text-delta } 1. TOC {:toc}



RegEX

=~ will look for partial match ==~ look for an exact match

Use with replace and findall

"LBlsBF4wUp".replaceAll(/[\d\sa-zA-Z.!?\-\']/)

Create String and compare

-closure for where-

Use groups

def replacedTxt = txt.replaceAll(/.*(\d{2}-\d{2}-\d{4}).*(Gr.*)./) { all, date, lang ->
    def dateObj = Date.parse('dd-MM-yyyy', date)
    "The text '$all' was created with $lang on a ${dateObj.format('EEEE')}."
}

Clone this wiki locally