Issue
When I try to run the following .sh code on my MacOS I get an error: "repetition-operator operand invalid"
Sounds like two repetition operators occur consecutively but I don't see that in regex. Maybe ".+?" is considered invalid syntax? Surprising
A code snippet:
export REGEX_DATETIME_DIFF="s/DATETIME_DIFF\((.+?),\s?(.+?),\s?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATETIME_DIFF(\1, \2, '\3')/g"
export REGEX_SCHEMA='s/`physionet-data.(mimiciii_clinical|mimiciii_derived|mimiciii_notes).(.+?)`/\2/g'
export CONNSTR='-d mimic'
{ echo "${PSQL_PREAMBLE}; DROP TABLE IF EXISTS code_status; CREATE TABLE code_status AS "; cat code_status.sql; } | sed -E -e "${REGEX_DATETIME_DIFF}" | sed -E -e "${REGEX_SCHEMA}" | psql ${CONNSTR}`
Any clue?
Solution
The regex (.+?),
matches a shortest substring followed by a comma and
can be substituted with ([^,]+),
. It is same with (.+?)`
. Then would you modify the 1st two lines as:
export REGEX_DATETIME_DIFF="s/DATETIME_DIFF\(([^,]+),\s?([^,]+),\s?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATETIME_DIFF(\1, \2, '\3')/g"
export REGEX_SCHEMA='s/`physionet-data.(mimiciii_clinical|mimiciii_derived|mimiciii_notes).([^`]+)`/\2/g'
Answered By - tshiono Answer Checked By - Robin (WPSolving Admin)