ismatch

ismatch(r::Regex, s::AbstractString) -> Bool

Test whether a string contains a match of the given regular expression.

Examples

  1. Check if a string matches a regular expression:

    julia> regex = r"a[bc]+d";
    julia> ismatch(regex, "abcd")
    true

    This example checks if the string "abcd" matches the regular expression r"a[bc]+d". The function returns true because the string matches the pattern.

  2. Verify if a string does not match a regular expression:

    julia> regex = r"[0-9]+";
    julia> ismatch(regex, "abc123")
    true

    This example checks if the string "abc123" contains a match for the regular expression r"[0-9]+". The function returns true because the string contains digits.

  3. Validate if a string matches a specific pattern:
    julia> regex = r"^[A-Z][a-z]+$";
    julia> ismatch(regex, "Julia")
    true

    It checks if the string "Julia" matches the regular expression r"^[A-Z][a-z]+$", which represents a string starting with an uppercase letter followed by one or more lowercase letters.

Common mistake example:

julia> regex = r"[0-9]+";
julia> ismatch(regex, "abc")
false

In this example, the string "abc" does not contain any digits, so it does not match the regular expression r"[0-9]+". The function correctly returns false in this case.

See Also

eachmatch, ismatch, match, matchall,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: