regex - Regular expression character class with parenthesis with grep command -


regular expression grep command. example let have file called regular.txt contain date below:

$ cat regular.txt     july     jul     fourth     4th     4    

so trying match these text input file,using below process method:

method 1: match fourth|4th|4

   $egrep '(fourth|4th|4)` regular.txt 

output method 1:

    fourth     4th     4    

method 2: match fourth|4th|4 using optional parenthesis

  $ egrep '(fourth|4(th)?)` regular.txt 

output method 2:

    fourth     4th     4    

method 3: match entire file july, jul, fourth, 4th, 4. using command below:

$ egrep 'july? (fourth|4(th)?)` regular.txt 

output method 3: nothing match here. how ?

could please me on ?

thanks,

your july? (fourth|4(th)?) regex matches sequence of patterns, jul followed optional y, space, , 2 alternatives: fourth or 4 optionally followed th substring.

if plan match jul or july 3rd alternative, add grouping construct:

'fourth|4(th)?|july?'               ^   ^^  

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -