简体   繁体   中英

Regex match any string not containing dot character

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

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.)

Try ^[^.]+$ . BTW, you don't need to escape dot inside [].

What about this:

^[^.]+$

Demo Regex

You can do:

^[^.]+$

or

^(?!.*\.).*$

Don't bother with regex for that, which is expensive. Here's a faster example (in php)

foreach($files as $file)
{
    // ignore dot files
    if( 0 === strpos($file,'.') ) continue;
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM