To what extent are RegEx engines compatible with one another?

纵饮孤独 提交于 2019-12-11 04:06:24

问题


I am creating regular expressions for work in R, using ESS in Emacs as my environment. R itself uses the PCRE engine, which is written in C and C++.

Question

I would like to know, if I send my code to somebody else, using a different version of R, perhaps in a completely different environment, will the RegEx work all the same? How often do you face an issue like this? Have you even seen one?

Logic tell me, that if the person is running my code, then they are using the same compiler etc. (of course you don't run R code in anything other than an R shell of some kind!) - however some things I have read have made me question this logic.

My findings

The answer may well be discernible from this site, but I don't understand enough to be certain. Here is an excerpt from StackOverflow's regex tag

The Perl programming language featured a significantly modified and enhanced version of Henry Spencer's regular expression library. With the release of Perl v5, further enhancements including lookaheads, lookbehinds, non-committing matches, non-capturing groups etc. were introduced. Through Philip Hazel's library reimplementation PCRE, these capabilities were made available in many other programming languages, including, but not limited to, PHP, Python, and R. Hence, Perl-Compatible Regular Expressions are the third main dialect of regular expressions in widespread use.

It does seem then that PCRE is good, but should I be worried that I am in Emacs and others might read my code in a different text editor (That text goes on to mention this problem)?

Extra Info

As a possible example of a compatibility issue: I am using the re-builder function in Emacs while looking at my huge text file, so I enter my regex in a mini-buffer and the matches are highlighted in the text displayed above. I finally nailed it, pasted this regex into my R code and... boom... it didn't get the job done. Maybe this will turn out to be an issue with the actual function I am using in R (gsub), but it still goes to show that compatibility issues exist. Here is the function which fails in R, but worked in Emacs' re-builder:

gsub("http:.*?[([:space:])| |\n]", "", x))

来源:https://stackoverflow.com/questions/33263759/to-what-extent-are-regex-engines-compatible-with-one-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!