Skip to content

Instantly share code, notes, and snippets.

@nlitwin
Created August 7, 2018 06:44
Show Gist options
  • Save nlitwin/1076a349666da70f5422a423b9675c77 to your computer and use it in GitHub Desktop.
Save nlitwin/1076a349666da70f5422a423b9675c77 to your computer and use it in GitHub Desktop.
Regex from Bash, VIM & Regex from Frontend Masters
# regular expressions
# system tools with regex: grep, sed, perl, vim, less
``` js
'1 two three \n'.replace(/1/, 'one')
```
similar to:
``` sh
echo '1 two three' | sed 's/1/one/'
```
# s/ means substitution
# sed -r and grep -E to not have to escape certain metacharacters
echo 'the the whatever dogs dogs etc' | sed 's/(\w+) \1/\1/g'
# prints the whatever dogs etc
# modify word in file
sed 's/cool/k001/g' -i file.txt
# perldoc perlreref docs for regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment