Skip to content

Instantly share code, notes, and snippets.

View kbbgl's full-sized avatar

Ko Ga kbbgl

View GitHub Profile
@kbbgl
kbbgl / a.sh
Created May 7, 2020 16:58
[match chunks 0+ times] #regex
# match 0 or more times using * quantifier
echo "hello, how are you?" | grep -e "[a-z]*" # will match hello, how, are, you
# match all numbers in chunks with length of one or more with + quantifier
echo "47427 8381481 5813471" | grep -P "[0-9]+"
echo "47427 8381481 5813471" | grep -P "\d+"
@kbbgl
kbbgl / q.sh
Created May 7, 2020 16:57
[match non-greedy] #regex
# using the ? means that we're not matching greedily
echo "<p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>" | grep -P "<p>.*?</p>" # will match <p>Paragraph 1</p>, <p>Paragraph 2</p>, <p>Paragraph 3</p>
# we can use the ? to match an optional character
echo "http:\\website.com,https:\\website2.com" | grep -P "https?.*"
@kbbgl
kbbgl / m.sh
Created May 7, 2020 16:57
[match x amount of times using iterations] #regex
# using the {x} will match whatever comes before it x amount of times
echo "12341234444412354444" | grep -P "4{3}" # will match 3 times '444'
# using the {x,y} will match a range from x to y
echo "12341234444344412354444" | grep -P "4{1,4}" # will match 4, 4444, 444, 4444[
@kbbgl
kbbgl / a.sh
Created May 7, 2020 16:56
[match x or inifinte times] #regex
# use {x,} to match string with x+ characters
echo "hello world reallylongword" | grep -P "\w{6,}" -o # will match reallylongword