Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex match any string not containing dot character

Tags:

for example match any folder name except files that have dot(.) before extension
I try [^\.] and .+[^\.].* nothing work

like image 914
hsgu Avatar asked Jan 08 '13 05:01

hsgu


People also ask

Does regex match dot space?

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

How do you escape a dot in regex?

(dot) metacharacter, and can match any single character (letter, digit, whitespace, everything). You may notice that this actually overrides the matching of the period character, so in order to specifically match a period, you need to escape the dot by using a slash \.

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 does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string).


1 Answers

You need to anchor it:

^[^.]+$

That will match a string composed of any characters except for dots. Is that what you mean by "before extension"? If you mean "at the beginning", then ^[^.] will do the trick.

But if this isn't, say, grep or something, and you have an actual programming language, this might be better accomplished there. (And even with grep it’s better to write just grep -v '^\.', for example.)

like image 194
Ry- Avatar answered Sep 19 '22 15:09

Ry-