使用Vala和GLib的Regex

使用Vala和GLib的Regex,regex,linux,glib,vala,Regex,Linux,Glib,Vala,有函数吗,类似的 使用GLib,我能找到的只有: public bool match_all_full (string str, ssize_t string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError Using the standard algorithm for regular expressi

有函数吗,类似的

使用GLib,我能找到的只有:

public bool match_all_full (string str, ssize_t string_len = -1, int start_position = 0,  RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError
Using the standard algorithm for regular expression matching only the longest match in the string is retrieved, it is not possible to obtain all the available matches. 
它还说,不可能获得所有可用的匹配项。

我找不到任何工作代码示例。谢谢你的帮助

注意:

目标是解析plist文件(我只需要CbundLeIdentifier和CbundLename值)

结果它给了我

** Message: main.vala:28: CFBundleIdentifier: cakephp
** Message: main.vala:28: CFBundleName: CakePHP
** Message: main.vala:28: DocSetPlatformFamily: cakephp
为什么不使用xmllib?
这个项目几乎没有依赖关系,在GNU系统中(尽管我是一个新手),如果我想要的话,程序打包时只假设一定的依赖关系“如果我的插件不可用,我想我只能使用可用的依赖项,否则我可能会破坏某些东西,从而阻止endsudoer的更新。

首先,让我们看看您引用的引用的上下文,并添加重点:

对于正则表达式匹配,使用标准算法只检索字符串中最长的匹配,不可能获取所有可用的匹配。例如,将“
”与模式“
”进行匹配,得到“

此函数使用不同的算法(称为DFA,即确定性有限自动机),因此它可以检索所有可能的匹配,所有匹配都从字符串中的同一点开始。例如,将“
”与模式“
”进行匹配,您将获得三个匹配项:“
”、“
”和“

这就是说,这并不是你要寻找的“全部”,你的案件要简单得多。您只需通过标准算法迭代匹配:

private static int main (string[] args) {
    string contents;
    GLib.Regex exp = /\<key\>([a-zA-Z0-9]+)\<\/key\>[\n\t ]*\<string\>([a-zA-Z0-9\.]+)\<\/string\>/;

    assert (args.length > 1);
    try {
        GLib.FileUtils.get_contents (args[1], out contents, null);
    } catch (GLib.Error e) {
        GLib.error ("Unable to read file: %s", e.message);
    }

    try {
        GLib.MatchInfo mi;
        for (exp.match (contents, 0, out mi) ; mi.matches () ; mi.next ()) {
            GLib.message ("%s: %s", mi.fetch (1), mi.fetch (2));
        }
    } catch (GLib.Error e) {
        GLib.error ("Regex failed: %s", e.message);
    }

    return 0;
}
private static int main(字符串[]args){
字符串内容;
GLib.Regex exp=/\([a-zA-Z0-9]+)\[\n\t]*\([a-zA-Z0-9\.]+)\/;
断言(args.length>1);
试一试{
GLib.FileUtils.get_contents(args[1],out contents,null);
}捕捉(油嘴滑舌的错误e){
GLib.error(“无法读取文件:%s”,e.message);
}
试一试{
GLib.MatchInfo-mi;
for(exp.match(contents,0,out mi);mi.matches();mi.next()){
GLib.message(“%s:%s”、mi.fetch(1)、mi.fetch(2));
}
}捕捉(油嘴滑舌的错误e){
GLib.error(“Regex失败:%s”,e.message);
}
返回0;
}

为什么不使用XML库?这应该使用XML库来完成,另请参见:您的答案很好,但这可能根本不起作用,因为不能保证和节点在同一行。谢谢大家,数据源是自动下载的zeal文档,它可能是一个比较可靠的数据源。我认为它也可以作为一个plist根据它的DTD进行验证。我将尝试上面的正则表达式解决方案:)
** Message: main.vala:28: CFBundleIdentifier: cakephp
** Message: main.vala:28: CFBundleName: CakePHP
** Message: main.vala:28: DocSetPlatformFamily: cakephp
private static int main (string[] args) {
    string contents;
    GLib.Regex exp = /\<key\>([a-zA-Z0-9]+)\<\/key\>[\n\t ]*\<string\>([a-zA-Z0-9\.]+)\<\/string\>/;

    assert (args.length > 1);
    try {
        GLib.FileUtils.get_contents (args[1], out contents, null);
    } catch (GLib.Error e) {
        GLib.error ("Unable to read file: %s", e.message);
    }

    try {
        GLib.MatchInfo mi;
        for (exp.match (contents, 0, out mi) ; mi.matches () ; mi.next ()) {
            GLib.message ("%s: %s", mi.fetch (1), mi.fetch (2));
        }
    } catch (GLib.Error e) {
        GLib.error ("Regex failed: %s", e.message);
    }

    return 0;
}