正则表达式零宽断言 grep sift ripgrep(rg)

<RecordId>12345</RecordId> 只想提取12345

1.grep 速度一般
type myXmlFile.xml|grep -oE "<RecordId>(.*)</RecordId>"|sed "s/<RecordId>//g;s/<\/RecordId>//g"

type myXmlFile.xml|d:\msys\opt\tools\bin\grep -oP "<RecordId>\K\w+"

type myXmlFile.xml|d:\msys\opt\tools\bin\grep -oP "<RecordId>\K\w+(?=</RecordId>)"

零宽断言
type myXmlFile.xml|d:\msys\opt\tools\bin\grep -oP "(?<=<RecordId>).*(?=</RecordId>)" 
                                                   后发断言         先行断言

2.sift 速度较快
type myXmlFile.xml|sift "<RecordId>(.*)</RecordId>" --replace "$1"

3.ripgrep 速度非常快
type myXmlFile.xml|rg "<RecordId>(.*)</RecordId>" -r "$1"

 

posted @ 2020-08-24 02:35  1CM  阅读(273)  评论(0编辑  收藏  举报