Negative Lookahead

Sort by

recency

|

38 Discussions

|

  • + 0 comments

    This problem does not support named backreferences

  • + 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 scanner = new Scanner(System.in);
            Pattern pattern = Pattern.compile("(.)(?!\\1)"); 
            // "\\1" is a backreference to the first captured group. It is a backreference which will be translated into the same character found in (.), whatever character that is.
            // Note: Does not work without parenthesis: ".(?!\\1)"
            Matcher matcher = pattern.matcher(scanner.next());
            int count=0;
            while(matcher.find()) count++;
            System.out.println("Number of matches : "+count);
        }
    }
    
  • + 0 comments

    (.)(?!\1)

  • + 0 comments

    see my regex

    r"(.)(?!\1)"
    
  • + 0 comments

    Regex_Pattern = r"(.)(?!\1)" # Do not delete 'r'.

    import re

    Test_String = input()

    match = re.findall(Regex_Pattern, Test_String)

    print("Number of