Code Scrappers


Pattern matching - The Wild Cards


' * '

~ Any number of characters including none.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap*
  chap1  chap2  chap3  chapone  chapthree  chaptwo
          



' ? '

~ Any single character.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap?
  chap1  chap2  chap3

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap???
  chapone  chaptwo
          



[ijk]

~ A single character either an i, j or k.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[123]
  chap1  chap2  chap3

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[12]
  chap1  chap2
            



[!ijk]

~ A single character that is not an i, j, or k.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[!1]
  chap2  chap3

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[!12]
  chap3
            



[a-z]

~ A single character that is within the ASCII range of characters a and z.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[a-z][a-z][a-z]
  chapone  chaptwo
            



[!a-z]

~ A single character that is not within the ASCII range of characters a and z.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap[!a-z]
  chap1  chap2  chap3
            



{pattern1,pattern2}

~ It matches the specified pattern.

  saarthak@DESKTOP-N01EJET:~/maths$ ls
  chap1  chap2  chap3  chapone  chapthree  chaptwo  sample

  saarthak@DESKTOP-N01EJET:~/maths$ ls chap{one,two}
  chapone  chaptwo