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

Solution Review: Searching a String

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

Contents


More Related Answers

  • Challenge: Searching a String

  • Solution Review: Searching a String

    0

    Task

    In this challenge, you were provided a string in which you had to find the first occurrence of a three-letter word. The only constraint was that the word must only contain lower-case letters.

    Solution

    The first thing you had to write was a regular expression which represented three-letter words only consisting of lower-case letters and store it in a variable. Something like this:

    val expressionToFind = "[a-z]{3}".r

    [a-z] specifies that the regular expression should only contain lower-case letters

    {3} specifies that the regular expression should have a length of 3.

    You then had to call the findFirstIn method on the regular expression and pass it the string you wanted to search. Recall that findFirstIn only finds the first occurrence of the specified regular expression.

    val match1 = expressionToFind.findFirstIn(stringToFindExpression)

    You can find the complete solution below:

    You were required to write the code on line 2 and line 3. 

    Popularity 1/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.