Regexp in C - match group

后端 未结 3 948
[愿得一人]
[愿得一人] 2021-01-15 04:25

I\'ve been struggling with regular expressions in C (just /usr/include/regex.h).


I have (let\'s say) hundreds of regexps and one of them can match

3条回答
  •  误落风尘
    2021-01-15 04:43

    "I have (let's say) hundreds of regexps ..."

    It looks like you are trying to comparing the quad parts of ip addresses. In general, in using regular expressions, its usually a red flag when using that many regex's on a single target and stopping after a match.

    example: Which group will correctly match first?
    target ~'American' , pattern ~ /(Ame)|(Ameri)|(American)/
    This does not even include quantifiers in the subgroups.

    If its the case of a constant form the regex's are composed of/from, for instance data, it might be better to use C's string functions to split out the data from the form into an array, then compare the array items with the target. C is much faster for this than regex's.

提交回复
热议问题