先読みアサーションを使用してください。
あなたは、文字列を別の部分文字列が含まれていないかどうかを確認したい場合は、あなたが書くことができます。
/^(?!.*substring)/
あなたがthis
とword
のためにも、先頭と行の終わりを確認する必要があります。
/^this(?!.*substring).*word$/
もう1つの問題は、検索文字列を使用していないこと、文章を探したいこと(自分の仕事の権利が分かっている場合)です。
だから解決策は次のようになります。使用方法の
perl -e '
local $/;
$_=<>;
while($_ =~ /(.*?[.])/g) {
$s=$1;
print $s if $s =~ /^this(?!.*substring).*word[.]$/
};'
例:
$ cat 1.pl
local $/;
$_=<>;
while($_ =~ /(.*?[.])/g) {
$s=$1;
print $s if $s =~ /^\s*this(?!.*regexp).*word[.]/i;
};
$ cat 1.txt
This sentence has the "regexp" word. This sentence doesn't have the word. This sentence does have the "regexp" word again.
$ cat 1.txt | perl 1.pl
This sentence doesn't have the word.
あなたのルールは混乱しているか、期待される結果を誤っています。なぜ "と"なぜ "いいえ"大きなテキストのテキスト。 – sjakubowski
@sjakubowski "部分文字列は 'this'で始まり、 'word'で終わります。" – Mathletics
この規則は混乱しますが正しいものです。私はGoogleで何かを見つけるのに多くの時間を費やしましたが、何も見つかりませんでした。 – Artem