Skip to content

Instantly share code, notes, and snippets.

@d3athkai
Last active January 5, 2024 02:37
Show Gist options
  • Save d3athkai/4c4969bcb75e5c2e9e8ab12c163e1d17 to your computer and use it in GitHub Desktop.
Save d3athkai/4c4969bcb75e5c2e9e8ab12c163e1d17 to your computer and use it in GitHub Desktop.
Regular Expression Tips and Tricks

Regular Expression Tips and Tricks

A collection of some of my useful Regular Expression Tips and Tricks.


Detect all variants of text

Given the following list of input:

1test2
test2
1test
test
test 123
#test
\test
@test
#$test
\$test

A regex .*[\S]* will match ALL from the input:

1test2
test2
1test
test
test 123
#test
\test
@test
#$test
\$test

Detect line containing specific character (eg: $)

Given the following list of input:

1test2
test2
1test
test
test 123
#test
\test
@test
#$test
\$test test

A regex .*[\S]*\$.* will match line containing $ from the input:

#$test
\$test test

Match exact whole word

Given the following list of input:

1test2
test2
1test
test
test 123

A regex \btest\b will match the exact word from the input:

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment