Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Pattern Matching with Match

Sumit Rawal answered on May 23, 2023 Popularity 9/10 Helpfulness 1/10

Contents


More Related Answers

  • regex all starting with
  • regex match word inside string
  • regex match either of two strings
  • string Pattern Search
  • regex match exact string
  • javascript regex all matches match
  • javascript regex example match
  • regex match any thing
  • Getting the string and the regex of the matched object
  • python loop on regexex match
  • regex.match
  • python re.search vs re.match
  • how to use the match function in javascript for regex
  • re.match python
  • Regular Expressions: Extract Matches
  • match all characters regex
  • Match an object in a string using ReGex
  • match regex
  • regex exact match
  • js regexp match
  • js regexp match
  • regex match either of two strings
  • python re search full match
  • String matching
  • string.regex match
  • re.search with regex python
  • find with regex
  • str.match
  • repeat pattern regex
  • String does not match the pattern of "^[\~|/|\\]".

  • Pattern Matching with Match

    0

    Pattern Matching

    Using match

    Syntax

    An Example

    Pattern Matching

    Pattern matching means exactly what you think it might—checking if an object or series of tokens match a specified pattern. A pattern match consists of a list of alternative cases which are made up of a pattern and a corresponding expression.

    Using match

    In Scala, pattern matching is done using the match expression. It is evaluated by taking the object to be matched and comparing it with each pattern in the order they are listed. The first pattern to match the object expression is selected and the corresponding expression is evaluated.

    Syntax

    selector is our object to be matched with the list of alternative patterns. Each case consists of a pattern followed by => which is further followed by an expression to be evaluated if its corresponding pattern is selected.

    An Example

    Let’s look at an example where given a food item, match matches it to its companion food.

    The code below, requires you to insert an input, the method of which has been discussed in a previous lesson. 

    Popularity 9/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.