Substitute 代替

Substitute replaces some or all of a string value returned by a measure with another string.Substitute メジャーから返された文字列値の一部または全部を別の文字列に置き換えます。

Optionsオプション

Substitute

A list of comma delimited "pattern":"replacement" pairs. All occurrences of pattern in the measure string value are replaced with replacement. For example, "This":"That" substitutes all occurrences of This with That.コンマ区切りの"pattern":"replacement"ペアのリスト。すべての出現箇所pattern測定文字列値が置き換えられますreplacement。たとえば"This":"That"Thisのすべての出現箇所をThatに置き換えます。

If multiple "pattern":"replacement" pairs are specified, each substitution is attempted in the specified order. For example, "This":"That","Here":"There" first replaces all occurrences of This with That and then replaces all occurrences of Here with There.複数の"pattern":"replacement"ペアが指定されている場合、各置換は指定された順序で試行されます。たとえば、"This":"That","Here":"There"最初にThisのすべての出現箇所Thatに置換し、次にHereのすべての出現箇所Thereに置換します

Each of the "pattern":"replacement" pairs are a separate action, and act on the results of the previous substitute pairs. For example, with "1":"One","10":"Ten", all occurrences of 1 are replaced with One, but occurrences of 10 will not be replaced with Ten, because the first substitution already changed all 1 characters to One. For the desired behavior, the order can be reversed as "10":"Ten","1":"One"."pattern":"replacement"ペアは別々のアクションであり、前の代替ペアの結果に基づいて動作します。たとえば、with "1":"One","10":"Ten"1の出現はすべてOneに置き換えられますが、10の出現はTenには置き換えられません。これは、最初の置換によってすでに1文字すべてがOneに変更されているためです。望ましい動作のために、順序は次のように逆にすることができます"10":"Ten","1":"One"

Instead of "pattern":"replacement", single quotes can be used either around the pattern or the replacement. (i.e. 'pattern':"replacement" or "pattern":'replacement', but not 'pattern':'replacement') This can be useful when either the pattern or the replacement contains double quotes. For example, '"':"double quote" replaces all occurrences of " with double quote.代わりに"pattern":"replacement"、単一引用符を使用することができますいずれかのパターンまたは交換を中心に。(すなわち'pattern':"replacement""pattern":'replacement'ではなく'pattern':'replacement'、パターンまたは交換のどちらかが二重引用符が含まれている場合)に便利です。たとえば'"':"double quote""のすべての出現箇所二重引用符で置き換えます

RegExpSubstitute Default: 0RegExpSubstitute デフォルト: 0

If set to 1, Perl compatible regular expressions can be used in the pattern part of Substitute pairs.に設定すると1Perl互換の正規表現patternSubstituteペアの一部に使用できます。

If captures are used in the pattern, (e.g. (.+)) they can be referenced in the replacement part using \1, (first capture) \2, (second capture) etc. The entire match can also be referenced with %%BODY%%.キャプチャがパターンで使用されている場合、(例えば(.+))それらは(最初のキャプチャ)、(2番目のキャプチャ)などreplacementを使用してパート内で参照できます。全体のマッチもで参照できます。\1\2%%BODY%%

Note: With RegExpSubstitute, a (capture) may not return an empty string. Care should be taken when using * (zero or more) quantifiers or (?(?= (If/Then) lookahead tests, as a capture must either cause the entire regular expression to "fail", or return a value of some kind.注: RegExpSubstituteでは、(capture)は空の文字列を返さない可能性があります。*(ゼロ以上の)数量詞や(?(?=(If / Then)先読みテストを使用する場合は、正規表現全体を「失敗」させるか、何らかの値を返す必要があるため、注意が必要です。

Examples

Normal substitution:通常の代入:

[MeasureYear]
Measure=Time
Format=%Y
Substitute="2012":"Twenty Twelve","2013":"Twenty Thirteen"
; Assuming that the current year is 2012, the string value of [MeasureYear] will
; be "Twenty Twelve" (without quotes). Since Substitute only affects the string
; value, the number value of [MeasureYear] will continue to be 2012.

[MeasureCalc1]
Measure=Calc
Formula=MeasureYear
; Since the number value of MeasureYear is used above, the value of [MeasureCalc1]
; will also be 2012.

[MeasureCalc2]
Measure=Calc
Formula=[MeasureYear]
DynamicVariables=1
; Since the string value of MeasureYear is used above, a syntax error will occur
; (as "Formula=Twenty Twelve" is not a valid formula).

Regular expression substitution:正規表現の置き換え

[MeasureEx1]
Measure=String
String=I am Rainy
RegExpSubstitute=1
Substitute="(\w+) (\w+) (\w+)":"\3, \1 \2","Rainy":"Yoda"
; Reorders the sentence and then replaces Rainy with Yoda.
; The result is: Yoda, I am

[MeasureEx2]
Measure=String
String=Hello, world!
RegExpSubstitute=1
Substitute="^(.{0,5}).+$":"\1..."
; Truncates string by length (in this case 5) and appends "...".
; The result is: Hello...

[MeasureEx3]
Measure=String
String=192.168.1.101
RegExpSubstitute=1
Substitute="^(\d{1,3}).(\d{1,3}).(\d{1,3}).\d{1,3}$":"\1.\2.\3.***"
; Masks an IP address. The result is: 192.168.1.***

関連記事

スポンサーリンク

Apacheをコマンドプロンプトから起動・停止・再起動する方法

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る