Created
April 26, 2023 05:44
-
-
Save yowcow/28ab7f328270e53fa928266549bef0e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Regexp Lookaround Memo | |
====================== | |
Lookahead | |
--------- | |
``` | |
❯ echo "hoge\nfuga\nhoge1\nfuga11\nhoge111\nfuga1111" | grep -P 'hoge(?=\d+)' | |
hoge1 | |
hoge111 | |
``` | |
Negative Lookahead | |
------------------ | |
``` | |
❯ echo "hoge\nfuga\nhoge1\nfuga11\nhoge111\nfuga1111" | grep -P 'hoge(?!\d+)' | |
hoge | |
``` | |
Lookbehind | |
---------- | |
``` | |
❯ echo "hoge\nfuga\n1hoge1\n11fuga11\n111hoge111\n1111fuga1111" | grep -P '(?<=\d)hoge' | |
1hoge1 | |
111hoge111 | |
``` | |
Negative Lookbehind | |
------------------- | |
``` | |
❯ echo "hoge\nfuga\n1hoge1\n11fuga11\n111hoge111\n1111fuga1111" | grep -P '(?<!\d)hoge' | |
hoge | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment