0

I'm studying Regex and I faced a example that convertes dates formats:

sed -r 's|([0-9]{2})/([0-9]{2})/([0-9]{4})|\3/\2/\1|' <<< 05/04/1947

Output:

1947/04/05

I understand why this works but I'm not sure why the author used | 'pipe' instead of '/' to separate the regexp, replacement and flags sections.

I think changing | to / would make the same output:

sed -r 's/([0-9]{2})/([0-9]{2})/([0-9]{4})/\3/\2/\1/' <<< 05/04/1947

Why the last example does not work like the first one?

Thanks!

Bart
  • 251
  • 4
  • 10
  • 2
    The first char behind `s` is the parameter separator. And the separator can be any char, but must not part of regex or replacement. In your example you use `/` as character, so it is forbidden. – Wiimm Apr 13 '20 at 18:41
  • @Wiimm Thanks! Now I got it. – Bart Apr 13 '20 at 18:55

0 Answers0