Why the same regular expression outputs different results in Linux and Windows?

30 views Asked by At

The script regexReplace("A1009.DCE", "\\D+", "") outputs different results in Linux and Windows.

Windows:

regexReplace("A1009.DCE", "\\D+", "")
A.CE

Linux:

regexReplace("A1009.DCE", "\\D+", "")
A1009CE
1

There are 1 answers

0
dbaa9948 On BEST ANSWER

This is attributed to the different implementations of regular expressions in Linux and Windows. The Linux version applies POSIX BRE (Basic Regular Expression) syntax provided by GNU grep, which does not support abbreviations such as “\D“. The Windows version applies C++'s standard regex library, which supports many regular expressions that cannot be parsed in Linux.