String haystack = "hello my name is people[${loop.index}].name";
Pattern pattern = Pattern.compile("\\$\\{\\w+(\\.\\w+)*\\}");
Matcher matcher = pattern.matcher(haystack);
List matches = new ArrayList();
while(matcher.find()){
matches.add(matcher.group());
}
The purpose of this blog is to document some of my experiences as a Java Developer in my day-to-day work and whilst learning new Java-related technologies. Hopefully other Java/ Web developers will find something useful here too or discover something new.
3 March 2010
Java Regular Expression Searching for Expression Language Script within a String
I recently needed to search for an Expression Language (el) script within a String e.g. "hello my name is people[${loop.index}].name". I decided to use RegEx as it's the most efficient solution. The following code snippet searches for multiple occurrences of el script blocks within a String and add's them to a List:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment