0
How to find the first repeated consecutive charater in string ?
Can we find it using regex ? If possible please tell regex pattern Example : '**:=1234561123' -> 1 '___commit___' -> m '1aabv2345568' -> a
5 Antworten
+ 3
In a regex pattern, whatever you put inside () will be a group. Also, you can match the xth group in a pattern by doing \x. For example, if I want the first and last characer to be the same in a string, I can use the pattern
r"^(.).+\1quot;
The \1 will match only if the character is the same as the character in the 1st group. Similarly, \2 will match the second group. Here is a demonstration
https://code.sololearn.com/c7XVdxNJTkR7/?ref=app
These are all the hints you need to solve your problem
+ 2
Ankeshwarapu Hitesh sorry, but if I tell you the exact pattern, then I would be solving your problem. I want you to solve your problem yourself. That is why I have given you all the hints as to what you need to solve it. If you didn't understand my explanation, let me know. I will link some sources.
Happy coding!
+ 1
I got it..🕺🕺
The pattern is
r"([a-zA-Z0-9])\1"
+ 1
Ankeshwarapu Hitesh correct
0
XXX
Thank you so much for answering my question..
Can u tell exact pattern for my examples ?