Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.regex

    Regex.isMatch

    Reports whether a leftmost-first search finds a match anywhere in the input.

    isMatch(text: string) -> bool
    Модуль
    std.regex →
    Получатель
    Regex
    Минимальное число аргументов
    1
    Максимальное число аргументов
    1

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    Import std.regex in language mode 5.21.

    The current compiler selects std/regex.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    Получатель

    Regex

    Ограничения параметров

    Regex.isMatch reports whether a match exists anywhere in the input. Regex.find returns Some containing the first match or None() when no match exists. Regex.findAll returns every nonoverlapping match in search order and returns an empty array when no match exists.

    Search begins at the earliest Unicode scalar boundary that permits the complete pattern to match. At that position alternatives are tried in pattern order. Greedy repetitions prefer more scalars and lazy repetitions prefer fewer scalars while still allowing the rest of the pattern to match.

    After a nonempty match, findAll resumes at its exclusive end. After an empty match, it resumes at the next Unicode scalar boundary. An empty match directly at the end of the preceding nonempty match is skipped and search advances to the next scalar boundary.

    An empty pattern visits every scalar boundary, including both ends. The empty input has one boundary and produces one empty match for an empty pattern. Matching never splits the UTF-8 bytes of a scalar.

    Regex.split and Regex.replaceAll use the same ordered match sequence as findAll. Repeated calls start a new search and do not retain a cursor. The input string and compiled pattern are unchanged.

    The receiver is evaluated once before the positional arguments, which are evaluated once from left to right. Search does not invoke user callbacks or access external state. No match is an ordinary result and does not produce a diagnostic.

    Результат

    The declared result type is bool.

    Эффекты

    Ошибки

    Result and effects

    Ссылка

    Reports whether a leftmost-first search finds a match anywhere in the input.

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.regex →

    Ссылка
    Правилоtopaz.stdlib.contract.regex-search.rule

    Search from the left and advance through nonoverlapping matches

    Regex.isMatch reports whether a match exists anywhere in the input. Regex.find returns Some containing the first match or None() when no match exists. Regex.findAll returns every nonoverlapping match in search order and returns an empty array when no match exists.

    Search begins at the earliest Unicode scalar boundary that permits the complete pattern to match. At that position alternatives are tried in pattern order. Greedy repetitions prefer more scalars and lazy repetitions prefer fewer scalars while still allowing the rest of the pattern to match.

    After a nonempty match, findAll resumes at its exclusive end. After an empty match, it resumes at the next Unicode scalar boundary. An empty match directly at the end of the preceding nonempty match is skipped and search advances to the next scalar boundary.

    An empty pattern visits every scalar boundary, including both ends. The empty input has one boundary and produces one empty match for an empty pattern. Matching never splits the UTF-8 bytes of a scalar.

    Regex.split and Regex.replaceAll use the same ordered match sequence as findAll. Repeated calls start a new search and do not retain a cursor. The input string and compiled pattern are unchanged.

    The receiver is evaluated once before the positional arguments, which are evaluated once from left to right. Search does not invoke user callbacks or access external state. No match is an ordinary result and does not produce a diagnostic.

    Причина

    One ordered match sequence makes searching, splitting, and replacement agree. Advancing after an empty match ensures progress without splitting a Unicode scalar. Boolean search is distinct from extracting Match data and does not introduce regex membership through the in operator.

    Choose the first successful alternative at the leftmost position

    Ссылка
    main.tpzChoose the first successful alternative at the leftmost positionОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. match (Regex.compile("a|ab")) {
    4. case Ok(pattern) => {
    5. match (pattern.find("zab")) {
    6. case Some(found) => io.writeLine("{found.start}:{found.end}:{found.text}")
    7. case None() => io.writeLine("no match")
    8. }
    9. let present = pattern.isMatch("zab")
    10. let absent = pattern.isMatch("zzz")
    11. io.writeLine("{present}:{absent}")
    12. match (pattern.find("zzz")) {
    13. case None() => io.writeLine("none")
    14. case Some(_) => io.writeLine("present")
    15. }
    16. let matches = pattern.findAll("zzz")
    17. io.writeLine("{matches.length}")
    18. }
    19. case Err(_) => io.writeLine("compile failed")
    20. }
    Ожидаемый выводКод завершения 0
    1:2:a
    true:false
    none
    0
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 1:2:a
    2. true:false
    3. none
    4. 0

    Choose a group alternative that allows the complete pattern to match

    Ссылка
    main.tpzChoose a group alternative that allows the complete pattern to matchОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. match (Regex.compile("(a|ab)c")) {
    4. case Ok(pattern) => {
    5. match (pattern.find("abc")) {
    6. case Some(found) => io.writeLine(found.text)
    7. case None() => io.writeLine("no match")
    8. }
    9. }
    10. case Err(_) => io.writeLine("compile failed")
    11. }
    Ожидаемый выводКод завершения 0
    abc
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. abc

    Return nonoverlapping matches in input order

    Ссылка
    main.tpzReturn nonoverlapping matches in input orderОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. match (Regex.compile("aa")) {
    4. case Ok(pattern) => {
    5. for found in (pattern.findAll("aaaaa")) {
    6. io.writeLine("{found.start}:{found.end}:{found.text}")
    7. }
    8. }
    9. case Err(_) => io.writeLine("compile failed")
    10. }
    Ожидаемый выводКод завершения 0
    0:2:aa
    2:4:aa
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 0:2:aa
    2. 2:4:aa

    Visit each boundary for an empty pattern and the empty input

    Ссылка
    main.tpzVisit each boundary for an empty pattern and the empty inputОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. match (Regex.compile("")) {
    4. case Ok(pattern) => {
    5. for found in (pattern.findAll("ab")) {
    6. io.writeLine("{found.start}:{found.end}")
    7. }
    8. io.writeLine("empty input")
    9. for found in (pattern.findAll("")) {
    10. io.writeLine("{found.start}:{found.end}")
    11. }
    12. }
    13. case Err(_) => io.writeLine("compile failed")
    14. }
    Ожидаемый выводКод завершения 0
    0:0
    1:1
    2:2
    empty input
    0:0
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 0:0
    2. 1:1
    3. 2:2
    4. empty input
    5. 0:0

    Skip an empty match directly after a nonempty match

    Ссылка
    main.tpzSkip an empty match directly after a nonempty matchОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. match (Regex.compile("a*")) {
    4. case Ok(pattern) => {
    5. for found in (pattern.findAll("ab")) {
    6. io.writeLine("{found.start}:{found.end}:{found.text}")
    7. }
    8. }
    9. case Err(_) => io.writeLine("compile failed")
    10. }
    Ожидаемый выводКод завершения 0
    0:1:a
    2:2:
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 0:1:a
    2. 2:2:

    Return no match after scanning a longer valid input

    Ссылка
    main.tpzReturn no match after scanning a longer valid inputОткрыть песочницу →
    1. import std.regex { Regex }
    2. import std.io
    3. let mut text = "a"
    4. for step in (0 .. 17) {
    5. text = text + text
    6. }
    7. match (Regex.compile("z")) {
    8. case Ok(pattern) => io.writeLine("{pattern.isMatch(text)}")
    9. case Err(_) => io.writeLine("compile failed")
    10. }
    Ожидаемый выводКод завершения 0
    false
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. false

    Меню

    Загрузка →