perl-5.38.0
    s/PATTERN/REPLACEMENT/msixpodualngcer

    Searches a string for a pattern, and if found, replaces that pattern with the replacement text and returns the number of substitutions made. Otherwise it returns false (a value that is both an empty string ("") and numeric zero (0) as described in "Relational Operators").

    文字列中でパターンを検索し、もし見つかれば、置換テキストで置き換え、 置換した数を返します。 見つからなければ、偽 (空文字列 ("") と数値のゼロ (0 の両方) を 返します。

    If the /r (non-destructive) option is used then it runs the substitution on a copy of the string and instead of returning the number of substitutions, it returns the copy whether or not a substitution occurred. The original string is never changed when /r is used. The copy will always be a plain string, even if the input is an object or a tied variable.

    /r (非破壊) オプションが使われると、文字列のコピーに対して置換が行われ、 置換された数ではなく、置換が行われたかどうかにかかわらずこのコピーが 返されます。 /r が使われた場合、元の文字列は決して変更されません。 コピーは、たとえ入力がオブジェクトや tie された変数でも、常に プレーンな文字列です。

    If no string is specified via the =~ or !~ operator, the $_ variable is searched and modified. Unless the /r option is used, the string specified must be a scalar variable, an array element, a hash element, or an assignment to one of those; that is, some sort of scalar lvalue.

    =~ 演算子や !~ 演算子によって文字列が指定されていなければ、 変数 $_ が検索され、修正されます。 /r が指定されていない限り、 =~ で指定される文字列は、スカラ変数、配列要素、ハッシュ要素、 あるいは、これらへの代入式といったある種の スカラ左辺値でなければなりません。

    If the delimiter chosen is a single quote, no variable interpolation is done on either the PATTERN or the REPLACEMENT. Otherwise, if the PATTERN contains a $ that looks like a variable rather than an end-of-string test, the variable will be interpolated into the pattern at run-time. If you want the pattern compiled only once the first time the variable is interpolated, use the /o option. If the pattern evaluates to the empty string, the last successfully executed regular expression is used instead. See perlre for further explanation on these.

    シングルクォートを区切り文字として使った場合には、 PATTERN にも REPLACEMENT にも変数展開を行ないません。 それ以外の場合、文字列の最後を表わすものには見えない $PATTERN に含まれると、実行時に変数がパターン内に展開されます。 最初に変数が展開されるときにだけパターンのコンパイルを行ないたいときには、 /o オプションを使ってください。 パターンの評価結果が空文字列になった場合には、最後に成功した正規表現が 代わりに使われます。 これについてさらに詳しくは、perlre を参照してください。

    Options are as with m// with the addition of the following replacement specific options:

    オプションは、m// のものに加えて、以下の置換固有のものがあります:

        e   Evaluate the right side as an expression.
        ee  Evaluate the right side as a string then eval the
            result.
        r   Return substitution and leave the original string
            untouched.
        e   式の右側の評価を行なう。
        ee  右側を文字列として評価して、その結果を評価する。
        r   置換した結果を返し、もとの文字列はそのままにする。

    Any non-whitespace delimiter may replace the slashes. Add space after the s when using a character allowed in identifiers. If single quotes are used, no interpretation is done on the replacement string (the /e modifier overrides this, however). Note that Perl treats backticks as normal delimiters; the replacement text is not evaluated as a command. If the PATTERN is delimited by bracketing quotes, the REPLACEMENT has its own pair of quotes, which may or may not be bracketing quotes, for example, s(foo)(bar) or s<foo>/bar/. A /e will cause the replacement portion to be treated as a full-fledged Perl expression and evaluated right then and there. It is, however, syntax checked at compile-time. A second e modifier will cause the replacement portion to be evaled before being run as a Perl expression.

    空白ではない任意の区切り文字で、スラッシュを置き換えられます。 識別子として許されている文字を使うときには s の後に空白を 追加してください。 先に述べたように、シングルクォートを使うと置換文字列での展開は されません (/e修飾子を使えば可能です)。 バッククォートを通常のデリミタとして扱うことに注意してください; 置換テキストはコマンドとして評価されません。 PATTERN を括弧類で括った場合には、REPLACEMENT 用にもう一組の区切り文字を 用意します; これは、括弧類であっても、なくてもかまいません; s(foo)(bar)s<foo>/bar//e は置換文字列を完全な Perl の式として扱い、その場所で直ちに解釈します。 しかし、これはコンパイル時に構文チェックされます。 二番目の e 修飾子を指定すると、置換部分がまず Perl の式として eval されます。

    Examples:

    例:

        s/\bgreen\b/mauve/g;              # don't change wintergreen
    
        $path =~ s|/usr/bin|/usr/local/bin|;
    
        s/Login: $foo/Login: $bar/; # run-time pattern
    
        ($foo = $bar) =~ s/this/that/;      # copy first, then
                                            # change
        ($foo = "$bar") =~ s/this/that/;    # convert to string,
                                            # copy, then change
        $foo = $bar =~ s/this/that/r;       # Same as above using /r
        $foo = $bar =~ s/this/that/r
                    =~ s/that/the other/r;  # Chained substitutes
                                            # using /r
        @foo = map { s/this/that/r } @bar   # /r is very useful in
                                            # maps
    
        $count = ($paragraph =~ s/Mister\b/Mr./g);  # get change-cnt
    
        $_ = 'abc123xyz';
        s/\d+/$&*2/e;               # yields 'abc246xyz'
        s/\d+/sprintf("%5d",$&)/e;  # yields 'abc  246xyz'
        s/\w/$& x 2/eg;             # yields 'aabbcc  224466xxyyzz'
    
        s/%(.)/$percent{$1}/g;      # change percent escapes; no /e
        s/%(.)/$percent{$1} || $&/ge;       # expr now, so /e
        s/^=(\w+)/pod($1)/ge;       # use function call
    
        $_ = 'abc123xyz';
        $x = s/abc/def/r;           # $x is 'def123xyz' and
                                    # $_ remains 'abc123xyz'.
    
        # expand variables in $_, but dynamics only, using
        # symbolic dereferencing
        s/\$(\w+)/${$1}/g;
    
        # Add one to the value of any numbers in the string
        s/(\d+)/1 + $1/eg;
    
        # Titlecase words in the last 30 characters only (presuming
        # that the substring doesn't start in the middle of a word)
        substr($str, -30) =~ s/\b(\p{Alpha})(\p{Alpha}*)\b/\u$1\L$2/g;
    
        # This will expand any embedded scalar variable
        # (including lexicals) in $_ : First $1 is interpolated
        # to the variable name, and then evaluated
        s/(\$\w+)/$1/eeg;
    
        # Delete (most) C comments.
        $program =~ s {
            /\*     # Match the opening delimiter.
            .*?     # Match a minimal number of characters.
            \*/     # Match the closing delimiter.
        } []gsx;
    
        s/^\s*(.*?)\s*$/$1/;        # trim whitespace in $_,
                                    # expensively
    
        for ($variable) {           # trim whitespace in $variable,
                                    # cheap
            s/^\s+//;
            s/\s+$//;
        }
    
        s/([^ ]*) *([^ ]*)/$2 $1/;  # reverse 1st two fields
    
        $foo !~ s/A/a/g;    # Lowercase all A's in $foo; return
                            # 0 if any were found and changed;
                            # otherwise return 1

    Note the use of $ instead of \ in the last example. Unlike sed, we use the \<digit> form only in the left hand side. Anywhere else it's $<digit>.

    最後の例で \ の代わりに $ を使っているのに注意してください。 sed と違って、\<数字> の形式はパターンの方でのみ使用できます。 その他の場所では、$<数字> を使います。

    Occasionally, you can't use just a /g to get all the changes to occur that you might want. Here are two common cases:

    ときには、/g を付けるだけでは、あなたが望んでいるような形で すべてを変更することができないことがあります。 良くある例を 2 つ示します:

        # put commas in the right places in an integer
        1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
    
        # expand tabs to 8-column spacing
        1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;

    While s/// accepts the /c flag, it has no effect beyond producing a warning if warnings are enabled.

    s////c フラグを受け付けますが、 警告が有効の場合に警告を出す以外の効果はありません。

クォート風演算子

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 258:

You forgot a '=back' before '=head2'

Around line 269:

=back without =over