【发布时间】:2009-07-31 09:14:26
【问题描述】:
我正在尝试编写一个函数来重复匹配正则表达式模式与输入字符串。该函数应将模式 1 与输入字符串匹配,并将其拆分为匹配和不匹配段的部分。随后将在那些不匹配的段上使用模式 2,直到使用所有输入模式。然后,返回参数将是所有子字符串的数组。
简单示例:
input string "abcdefgh" against patterns "bc" and "f", would first split it into "a", "bc" and "defgh". Subsequently pattern "f" would be run against the "a" and "defgh" part and splitting the later into "de", "f", and "gh". Return argument {"a", "bc", "de", "f", "gh"}
(我还会保留一个带有匹配/不匹配信息的关联数组)
但我的问题是:哪种数据结构最适合执行此类任务?以及如何最好地解决这个问题,感觉就像是以递归方式工作的东西。
【问题讨论】:
标签: c algorithm data-structures