Groovy web console

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

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'   
},    
"Microsoft-Dylon"{ 
'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 << m.group(1).replace("-", "") 
}
println extractedData