Can these two regular expression expressions give a different result?

Can these two regular expression expressions give a different result?

perl -pe 's/.*c//s'

perl -0777 -pe 's/.*c//s'

Where .*ccan I replace anything ..

In case the .*cresult will be the same

$ echo -e 'a\nb\nc\nd' | perl -pe 's/.*c//s'
a
b

d

$ echo -e 'a\nb\nc\nd' | perl -0777 -pe 's/.*c//'
a
b

d

And the question is re the difference between regular expressions, where that echo can be replaced with something too.

Are -0777and /sinterchangeable?

And it makes no sense to do as -0777with /s?

+4
source share
2 answers

They mean completely different things and are not interchangeable, although in some cases they may have the same result.

  • /sIt is making .a coincidence all the characters (including the line); without it .usually means[^\n]
  • -0777 ;

/s , -0 .

-0777 , ( /s ). , , /s .

( ), c, , :

echo -e 'a\nb\nc\nd' | perl -0777 -pe 's/.*c//s'

:

d
+3

Qtax , , , .

$ echo -e 'a\nb\nc\nd' | perl -pe 's/./o/s'
o
o
o
o


$ echo -e 'a\nb\nc\nd' | perl -0777 -pe 's/./o/'
o
b
c
d

$ echo -e 'aa\nbb\ncc\ndd' | perl -0777 -pe 's/./o/'
oa
bb
cc
dd

$ echo -e 'aa\nbb\ncc\ndd' | perl -pe 's/./o/s'
oa
ob
oc
od

$ echo -e 'aa\nbb\ncc\ndd' | perl -pe 's/./o/sg'
oooooooooooo

$ echo -e 'aa\nbb\ncc\ndd' | perl -0777 -pe 's/./o/g'
oo
oo
oo
oo

, -0777 /s .

+2

All Articles