Шаблон:Str/count/doc

Материал из Dwarf Fortress Wiki
< Шаблон:Str/count
Версия от 11:04, 15 августа 2024; GeloMor (обсуждение | вклад) (Новая страница: «Essentially {{tl|str/len}}, but counts the number of times {{{<nowiki/>1}}} appears in {{{<nowiki/>2}}}. Note that {{{<nowiki/>1}}} can be any regular expression. ==Examples== <pre>{{str/count|a|abca}}</pre> → {{str/count|a|abca}} <pre>{{str/count|\d|abc 123}}</pre> → {{str/count|\d|abc 123}} <pre>{{str/count|\D|abc 123}}</pre> → {{str/count|\D|abc 123}} <pre>{{str/count|\w+|this is an example}}</pre> &rar...»)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигацииПерейти к поиску

Essentially {{str/len}}, but counts the number of times {{{1}}} appears in {{{2}}}.

Note that {{{1}}} can be any regular expression.

Examples

{{str/count|a|abca}}

→ 2

{{str/count|\d|abc 123}}

→ 3

{{str/count|\D|abc 123}}

→ 4

{{str/count|\w+|this is an example}}

→ 4 (\w+ matches one or more "word" characters, but not spaces)

  {{str/count|\[\[[^]]+\]\]|This is text with a [[link]] and [[another link]].}}

→ 2

Breakdown of regular expression:

Section Meaning Explanation
\[\[ [[ Two literal [ characters (note that [ and ] have a special meaning in regular expressions).
[^]] Any character that is not ] A character class -- matches all characters listed between the brackets. The ^ is the negation operator, causing all characters not listed to be matched instead. In this case, the first ] is the only character matched, since the second is the closing bracket. The first bracket is not treated as the closing bracket, since an empty character class is invalid.
+ Allows one or more matches of the previous expression (in this case, it allows the non-] characters to be repeated)
\]\] ]] Matches two literal ] characters.