Need help retrieving substrings using REGEX (Coldfusion 8)
Posted on 2009-04-24
I need a function which returns certain substrings of a slightly larger string. Sample string would be:
"[one][two][three]", would return "one", "two", "three".
I cannot just split using "" as delimiters how ever since anything could appear imbetween the entries, i.e:
"abc [one]/[two] good morning [three].pdf", and this should still return "one", "two", "three".
Left to my own devises i would be inclined to get the indexes of "[" and "]" alternatively, grabbing subsequent substrings, but think this is both inelegant and likely slow?? Would i be right in thinking that best solution would involve regex? I am not familiar with the regex expression paths, so if this is the correct tool to use can anyone provide me a simple code sample (in Coldfusion) for retrieving the values for the sample output above? The response can be an array, list or anything manageable.
If regex is not the best way then perhaps you can suggest something better. Side note: the sample input is typically no more than 40-50 characters.