Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression to match one or two dots [duplicate]

Tags:

java

regex

What is the regular expression for . and .. ?

if(key.matches(".")) {  do something   } 

The matches accepts String which asks for regular expression. Now i need to remove all DOT's inside my MAP.

like image 627
John Avatar asked Oct 05 '10 09:10

John


People also ask

How do you match a dot in regex?

in regex is a metacharacter, it is used to match any character. To match a literal dot in a raw Python string ( r"" or r'' ), you need to escape it, so r"\." Unless the regular expression is stored inside a regular python string, in which case you need to use a double \ ( \\ ) instead.

What is the regular expression matching one or more specific characters?

The character + in a regular expression means "match the preceding character one or more times". For example A+ matches one or more of character A. The plus character, used in a regular expression, is called a Kleene plus .

Does regex match dot space?

Yes, the dot regex matches whitespace characters when using Python's re module.

What is ?= * In regular expression?

. Your regex starts with (?= (ensure that you can see, but don't consume) followed by . * (zero or more of any character).


1 Answers

. matches any character so needs escaping i.e. \., or \\. within a Java string (because \ itself has special meaning within Java strings.)

You can then use \.\. or \.{2} to match exactly 2 dots.

like image 135
mikej Avatar answered Sep 23 '22 15:09

mikej