For "Is there any special bash reserved characters in bash regex expression?"
The simple answer is yes.As for an example:
url="https://www.youtube.com/playlist?list=PLmHVyfmcRKyxvxehq3fiGjKDsEyy6d4Tz" regex='^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list=' idx=0 (( idx++ )) # normal if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex - $idx"; fi (( idx++ )) # normal if [[ $url =~ $regex ]]; then echo "URL matches the regex - $idx"; fi (( idx++ )) yt='www\.youtube\.com\/' if [[ $url =~ ^https:\/\/${yt}playlist\?(.+&)?list= ]]; then echo "URL matches the regex - $idx"; fi (( idx++ )) if [[ $url =~ ^https:\/\/'${yt}'playlist\?(.+&)?list= ]]; then echo "URL matches the regex - $idx"; fi (( idx++ )) if [[ $url =~ '^https:\/\/'${yt}'playlist\?'(.+&)?list= ]]; then echo "URL matches the regex - $idx"; fiI guess its better to change the question:
from
"Is there any special bash reserved characters in bash regex expression?"
to
"How quotes work in bash regex expression? (Regarding special regex reserved character & special bash reserved characters.)"(Was expecting a way to write literal regex, that would be so much easier, seems not possible.)
(see update below: use single quote')
Became Hot Network Question
Vilinkameni
- 1.6k
- 1
- 7
- 15
