Regex for majordomo alias file
Posted: Fri Feb 03, 2006 4:59 pm
Hi all,
I've been charged with the task of parsing througha Majordomo alias file and pulling out all aliases. The format of the lines I'm concerned with is:
<alias name>:<whitespace> [ [<entry>,{0,1}]* | <entry>]
Which basically means I could have either:
aliasname: entry1, entry2, entry3
-OR-
aliasname: entry
I've got my expression to the point where I can pull out the alias name and all the entries as a single string (ie: 'entry1,entry2,entry3'). That expression is:
Now, I want to see if I can modify that expression so that it also pulls out EACH entry from the list if it exists. So, I'd like preg_match() to give me
[0] server: entry1,entry2,entry3
[1] server
[2] entry1
[3] entry2
[4] entry3
I *think* this can be accomplished with looking ahead or looking back in the expression, but it's honestly out of my mental capacity to figure out how. I was thinking this might work, but I was proven wrong:
If anyone has any ideas, it would be greatly appreciated. Or, if you know this can't be done, please let me know and I'll do it an alternative way.
Thanks folks!
I've been charged with the task of parsing througha Majordomo alias file and pulling out all aliases. The format of the lines I'm concerned with is:
<alias name>:<whitespace> [ [<entry>,{0,1}]* | <entry>]
Which basically means I could have either:
aliasname: entry1, entry2, entry3
-OR-
aliasname: entry
I've got my expression to the point where I can pull out the alias name and all the entries as a single string (ie: 'entry1,entry2,entry3'). That expression is:
Code: Select all
/(.*?):\s*(.*)/[0] server: entry1,entry2,entry3
[1] server
[2] entry1
[3] entry2
[4] entry3
I *think* this can be accomplished with looking ahead or looking back in the expression, but it's honestly out of my mental capacity to figure out how. I was thinking this might work, but I was proven wrong:
Code: Select all
/(.*?):\s*(?:(.*?),*)*/If anyone has any ideas, it would be greatly appreciated. Or, if you know this can't be done, please let me know and I'll do it an alternative way.
Thanks folks!