"(" の後にすべてを表示するための私の正規表現:
echo "apples (orange) (plum)" | sed -re 's/^.+\(//'
出力: plum)
期待される出力:orange) (plum)
最後の文字ではなく、最初に出現する文字をキャッチするにはどうすればよいですか?
Can't. .* and .+ are always greedy. There are other ways to accomplish this though.
Delete all leading non-(
's
$ sed 's/[^(]*(//' <<<'apples (orange) (plum)'
orange) (plum)
Or almost equivalent and not really an improvement would be saving the second part using a group.
$ sed 's/[^(]*(\(.*\)$/\1/' <<<'apples (orange) (plum)'
orange) (plum)
echo "apples (orange) (plum)" | sed -re 's/^[^(]+\(//'
. は任意の文字に一致するため、sed は行の最後の括弧を監視します。したがって、.
数学(
と ^[^(]+\(
数学apples (orange) (
。したがって、あなたが提案する[^(]*
ように、まったく一致しないように使用する必要があります。(