简体   繁体   English

通过tre库使用近似匹配查找多个正则表达式匹配

[英]Finding multiple regex hits using approximate matching via the tre library

Using C, I'm trying to find the location and number of matches of a substring within another parent string. 我正在尝试使用C查找另一个父字符串中子字符串的位置和匹配数。 Because I also need to include approximate (hamming distance) matches, I'm using the tre library found here: http://laurikari.net/tre/ . 因为我还需要包含近似(汉明距离)匹配项,所以我使用的tre库位于: http : //laurikari.net/tre/

I'm having trouble understanding some of the documentation on the site, likely because I'm not too familiar with regex lingo. 我在理解站点上的某些文档时遇到了麻烦,可能是因为我对regex术语不太熟悉。 According to the tre documentation, I can get more specific information about 'submatches'. 根据tre文档,我可以获得有关“子匹配”的更多具体信息。 Are these the matches I'm looking for? 这些是我要找的比赛吗?

Thanks! 谢谢!

To answer a part of your question about sub-matches: take the example string: 要回答有关子匹配的问题,请使用以下示例字符串:

"noise aaa123bbb456ccc more noise"

and the regex: 和正则表达式:

aaa(.*?)bbb(.*?)ccc

then the entire match holds aaa123bbb456ccc which has two sub-matches in it: 123 and 456 . 那么整个比赛将保留aaa123bbb456ccc ,其中有两个子比赛: 123456 These sub-matches are also called groups (the strings that are matched by the part of the regex between parenthesis). 这些子匹配也称为组(由括号之间的正则表达式部分匹配的字符串)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM