
最初のペア<>の間の文字列を削除したいです。
オリジナル:
< a href="ACM-Reference-Format.dbx"> ACM-Reference-Format.dbx < /a >
私の考えでは
ACM-Reference-Format.dbx</a>
使ってみよう
sed 's/[<->]*/ but it only removed the first <
答え1
正規表現では、[]
角かっこの間のすべての文字に一致する文字クラスが定義されます。たとえば、azとの間のアルファベット文字を一致させることができます[a-z]
。これはあなたの例には役立ちません。
代わりに、欲しいものは一致、ランダム<
な文字、その後にあります>
。
一般的には使用できますが、<.*?>
Pankiが指摘したように、sed
貪欲ではない一致はサポートされていません。
>
そして、以下を除くすべての文字を一致させることができます/
。
sed 's/<[^>\/]*>\s//'
例:
─$ echo "< a href="ACM-Reference-Format.dbx"> ACM-Reference-Format.dbx < /a > " | sed 's/<[^>\/]*>\s//'
ACM-Reference-Format.dbx < /a >
説明する:
<[^>\/]*>
< #matches <
[^ ] #negated character class, matches any character except the ones specified
> / #the characters not to be matched
\ #escaping the following slash to prevent it from being interpreted as special symbol
* #matches previous character between 0 and infinity times
> #matches >
答え2
次のことができます。
$ sed 's/[^>]*> \([^>]*\)/\1/' file # or string
ACM-Reference-Format.dbx < /a >