Matching Specific String

Sort by

recency

|

68 Discussions

|

  • + 0 comments

    Python3

    Regex_Pattern = r'hackerrank'
    
    import re
    
    Test_String = input()
    
    match = re.findall(Regex_Pattern, Test_String)
    
    print("Number of matches :", len(match))
    
  • + 0 comments

    \w{3}\W\w{10}\W\w{3}

  • + 0 comments

    Java 15:

    import java.io.*;
    import java.util.*;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            Pattern pattern = Pattern.compile("hackerrank");
            int count = 0;
            while(sc.hasNext())
            {   Matcher matcher = pattern.matcher(sc.next());
                if (matcher.find()) count++;
            }
            System.out.println("Number of matches : "+count);
        }
    }
    
  • + 0 comments

    java solution

    import java.io.*;
    import java.util.*;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            Pattern pattern = Pattern.compile("hackerrank");
            int count = 0;
            while (scanner.hasNext()) {
                Matcher matcher = pattern.matcher(scanner.next());
                if (matcher.find()) count++;
            }
            System.out.println("Number of matches : " + count);
        }
    }
    
  • + 0 comments

    This got me confused, I thought what the task wants is to search characters between the "." in example URL. so I used this regex "(?<=.).(?=.)" however it seems it only requires to search for "hackerrank" string only. My reading comprehension is too rusty.