--Confirmation environment: sed (GNU sed) 4.2.2 --There are parts that behave differently from regular expressions in PHP, JavaScript, and VSCode. ――In conclusion, I think you can't do anything that isn't written in the sed manual. ――The regular expression engine I'm used to is Oniguruma, so it feels strange.
--s /
represents permutation
--sed's / search character / replacement character /'
--When you want to capture -r
--When using capture, \
sed -r's / search (character) / \ 1 /'
--Basically, there is a habit around capture
--\ s
cannot be used[\ t \ n \ v \ f \ r \ x20]
can be used instead
--I have a habit of capturing (Is the behavior of ?
Different?)
--When you do /.+?"Records ":" (. +?) ". + /
To the following text, PHP, JS, VSCode will cost $ 1
ʻa @ 163.43.80.45 \ nmx @ 10 \ ntxt .... can be captured --
sed -r's /. +?" Records ":" (. +?) ". + / \ 1 /' ʻa @ 163.43.80.45 \ nmx @ 10 \ ntxt .... "," ttl ":" 60 "}," request_id ":" 202010191733159039640087223V "," request ": {"path ":" /v1/domains/example.com/dns "," method ":" GET "," params
Become
--You need to do sed -r's /. +?" Records ":" ([^ "] +?)". + / \ 1 /'
to get the expected result.
{"results":{"domainid":6526946,"domainname":"example.com","ns_type":"foobarbaz","records":"a @ 163.43.80.45\nmx @ 10\ntxt ....","ttl":"60"},"request_id":"202010191733159039640087223V","request":{"path":"/v1/domains/example.com/dns","method":"GET","params":[]}}
――After all there is a habit of capturing
--When you do / ^ (?: [^] +? +?) {3} ([^] +). + /
For the following text, in PHP, JS, VSCode, it is $ 1
and 1.0
Can be captured
--sed -r's / ^ (?: [^] +? +?) {3} ([^] +). + / \ 1 /'
gives the following error sed: -e expression # 1, char 33: Invalid preceding regular expression
--You need to use sed -r's / ^ ([^] +? +?) {3} ([^] +). + / \ 2 /'
to get the expected result.
--Maybe you can't use ?:
(I think you can't use non-capturing group in sed)
root 51849 0.0 1.0 7488 812 ? Sl Oct16 0:52 docker-containerd-shim
Recommended Posts