我们有任何模式匹配字符串搜索吗?/

时间:2012-01-30 09:19:49

标签: c linux string

我有以下字符串格式。

({'BTAddress': <'00:22:58:07:76:9B'>, 'Name': <'Some-Name'>, 'Alias': <'some-Name'>, 'Class': <uint32 12316>, 'Adapter': <objectpath '/org/bluez/3196/hci0'>},)

我想在C中解析上面的字符串而不是做原始解析,任何使用模式解析的建议? 谢谢你的帮助。

4 个答案:

答案 0 :(得分:1)

您可以使用strtokhttp://www.cplusplus.com/reference/clibrary/cstring/strtok/。 你必须做一些手工工作才能使它工作,但它运作正常。

注意:您传递的char指针将被操纵!!

答案 1 :(得分:1)

任何符合POSIX标准的C编译器都应提供<regex.h>,为您提供应该能够提供帮助的正则表达式。

答案 2 :(得分:0)

正则表达式库可能就是您所需要的。如果您使用的是具有regular expression库的GNU C库,则为pattern matching。对于Win32编译器,您可以使用GNU代码的Regex for Windows端口。

答案 3 :(得分:0)

我的建议如下:

 A) try using strtok to split the text at ',' and then split the resulting subtexts only once at ':' ,that way you would get the key,value pairs you desire.
 B) use a regEx api under C that would basically solve your issue. 

另外我可能会建议在C下为你的解析文本寻找一个键值存储(C ++有一个,但我真的不知道C)

相关问题