Groovy web console

subscribe to the feed Subscribe
to this
Groovy extracting string content (via #groovywebconsole)
tweet this snippet Tweet

Groovy extracting string content

Published 10 months ago by Nitin Dhomse
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.regex.Matcher
import java.util.regex.Pattern
String text = '''
biodata: {
    "IBM-Ruby" {    
'Expertise= web development',    
'EXperience= 5 years'   
'Expertise= Java',       
'EXperience"= 2 years'  

  String fileContent = text
Pattern p = Pattern.compile("-([A-Za-z0-9]*)") 
Matcher m = p.matcher(fileContent) 
List extractedData = []
while (m.find()) {     
// Adding extracted data to the list    

extractedData <<"-", "") 
println extractedData