Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のような行を含むファイルがあります
I want a lot <*tag 1> more <*tag 2>*cheese *cakes.
* を削除しようとしています<>が、外側ではありません。タグは上記よりも複雑になる場合があります。たとえば、<*better *tag 1>.
<>
<*better *tag 1>
を試してみましたが/\bregex\b/s/\*//g、これはタグ 1 では機能しますが、タグ 2 では機能しません。
/\bregex\b/s/\*//g
どうもありがとう。
必須の Perl ソリューション:
perl -pe '$_ = join "", map +($i++ % 2 == 0 ? $_ : s/\*//gr), split /(<[^>]+>)/, $_;' FILE
追加:
perl -pe 's/(<[^>]+>)/$1 =~ s(\*)()gr/ge' FILE