How to do regex string replacements in pure C?

前端 未结 3 1795
旧时难觅i
旧时难觅i 2020-12-25 15:15

I\'ve looked at the regex functions in the POSIX regex library and the PCRE library, but both of them don\'t seem to have a string replacement function. I don\'t want to use

3条回答
  •  礼貌的吻别
    2020-12-25 15:53

    The PCRE library itself does not provide a replace function, but there is a wrapper function available at the PCRE downloads page that accepts perl style =~ s/pattern/replace/ syntax and then uses the PCRE native functions to do a substitute/replace for you. Go to http://www.pcre.org/ then click on the Download link: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/, then the Contrib directory. The package/project you want is: pcrs-0.0.3-src.tar.gz.

    Note that I have not used this myself so I cannot testify as to how well it works. It is a fairly small and simple piece of code however, so it may well serve your purpose nicely.

提交回复
热议问题