Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -111,7 +111,43 @@ 111 111 } 112 112 {{/code}} 113 113 ))) 114 +* The ##$regextool## [[Velocity Tool>>extensions:Extension.Velocity Module||anchor="HVelocityTools"]] has a new method:((( 115 +{{code language="java"}} 116 +/** 117 + * @param content the content to parse 118 + * @param regex the regular expression to look for in the passed content 119 + * @return an empty list if the passed regular expression doesn't match the content, several {@link RegexResult} 120 + * objects containing the matched position and matched content for all capturing groups and sub-groups 121 + * otherwise 122 + */ 123 +public List<List<RegexResult>> findAll(String content, String regex) 124 +{{/code}} 114 114 126 +We had to add a new method because the existing ##RegexTool#find(String, String)## returns information about only the first capturing group. Here's a test to show how the new method works: 127 + 128 +{{code language="java"}} 129 +@Test 130 +public void findAll() 131 +{ 132 + RegexTool tool = new RegexTool(); 133 + List<List<RegexResult>> result = 134 + tool.findAll("one :two three (:four) five :six seven=:eight", ":(\\w+) (\\w+)"); 135 + 136 + Assert.assertEquals(2, result.size()); 137 + Assert.assertEquals(":two three", result.get(0).get(0).getGroup()); 138 + Assert.assertEquals(":six seven", result.get(1).get(0).getGroup()); 139 + 140 + Assert.assertEquals(3, result.get(0).size()); 141 + Assert.assertEquals("two", result.get(0).get(1).getGroup()); 142 + Assert.assertEquals("three", result.get(0).get(2).getGroup()); 143 + 144 + Assert.assertEquals(3, result.get(1).size()); 145 + Assert.assertEquals("six", result.get(1).get(1).getGroup()); 146 + Assert.assertEquals("seven", result.get(1).get(2).getGroup()); 147 +} 148 +{{/code}} 149 +))) 150 + 115 115 == Deprecated and Retired projects == 116 116 117 117 * XML-RPC module have been moved to https://github.com/xwiki-contrib/xwiki-platform-xmlrpc