问题
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