Skip to content

Commit

Permalink
[demo] Test cases for ^ and replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed Jan 31, 2024
1 parent f275ce7 commit a821fc2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions demo/survey-replace.sh
Expand Up @@ -64,6 +64,10 @@ regex() {
# supports equivalent of $0 and $1 ?
python3 -c 'import re; p = re.compile("[i](.)"); print(p.sub("[\g<0>]", "oils-for-unix"))'
python3 -c 'import re; p = re.compile("[i](.)"); print(p.sub("[\g<1>]", "oils-for-unix"))'

# ^ means that only one replacement occurs
python3 -c 'import re; p = re.compile(r"(\d+)"); print(p.sub("[\g<1>]", "9-16-25"))'
python3 -c 'import re; p = re.compile(r"^(\d+)"); print(p.sub("[\g<1>]", "9-16-25"))'
echo

echo 'REGEX JS'
Expand All @@ -87,6 +91,11 @@ regex() {
nodejs -e 'console.log("oils-for-unix".replace(new RegExp("[i](.)", "g"), "[$0]"))'
nodejs -e 'console.log("oils-for-unix".replace(new RegExp("[i](.)", "g"), "[$&]"))'
nodejs -e 'console.log("oils-for-unix".replace(new RegExp("[i](.)", "g"), "[$1]"))'

# ^ means that only one replacement occurs
nodejs -e 'console.log("9-16-25".replace(new RegExp("(\\d+)", "g"), "[$&]"))'
nodejs -e 'console.log("9-16-25".replace(new RegExp("^(\\d+)", "g"), "[$1]"))'
echo
}

"$@"

0 comments on commit a821fc2

Please sign in to comment.