regex match all not PDF files [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Regex pattern that does not match certain extensions?
5 answers
Regular expression for excluding file types .exe and .js
3 answers
preg_match('/.(?!pdf)$/', $file)
I want to match all files except pdf files
path/file.jpg # match
path/file.png # match
path/file.pdf # not match
php regex
marked as duplicate by revo
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:06
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Regex pattern that does not match certain extensions?
5 answers
Regular expression for excluding file types .exe and .js
3 answers
preg_match('/.(?!pdf)$/', $file)
I want to match all files except pdf files
path/file.jpg # match
path/file.png # match
path/file.pdf # not match
php regex
marked as duplicate by revo
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:06
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
if the file has a name likepath/pdf_file.png
– executable
Jan 3 at 10:46
match all files except pdf files
– clarkk
Jan 3 at 10:47
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
You should not use all the recommended complicated regular expressions below. Use$(?<!.pdf)
instead.
– revo
Jan 3 at 12:08
add a comment |
This question already has an answer here:
Regex pattern that does not match certain extensions?
5 answers
Regular expression for excluding file types .exe and .js
3 answers
preg_match('/.(?!pdf)$/', $file)
I want to match all files except pdf files
path/file.jpg # match
path/file.png # match
path/file.pdf # not match
php regex
This question already has an answer here:
Regex pattern that does not match certain extensions?
5 answers
Regular expression for excluding file types .exe and .js
3 answers
preg_match('/.(?!pdf)$/', $file)
I want to match all files except pdf files
path/file.jpg # match
path/file.png # match
path/file.pdf # not match
This question already has an answer here:
Regex pattern that does not match certain extensions?
5 answers
Regular expression for excluding file types .exe and .js
3 answers
php regex
php regex
edited Jan 3 at 11:15


splash58
21.9k31225
21.9k31225
asked Jan 3 at 10:45
clarkkclarkk
8,01248145239
8,01248145239
marked as duplicate by revo
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:06
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by revo
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 12:06
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
if the file has a name likepath/pdf_file.png
– executable
Jan 3 at 10:46
match all files except pdf files
– clarkk
Jan 3 at 10:47
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
You should not use all the recommended complicated regular expressions below. Use$(?<!.pdf)
instead.
– revo
Jan 3 at 12:08
add a comment |
if the file has a name likepath/pdf_file.png
– executable
Jan 3 at 10:46
match all files except pdf files
– clarkk
Jan 3 at 10:47
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
You should not use all the recommended complicated regular expressions below. Use$(?<!.pdf)
instead.
– revo
Jan 3 at 12:08
if the file has a name like
path/pdf_file.png
– executable
Jan 3 at 10:46
if the file has a name like
path/pdf_file.png
– executable
Jan 3 at 10:46
match all files except pdf files
– clarkk
Jan 3 at 10:47
match all files except pdf files
– clarkk
Jan 3 at 10:47
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
You should not use all the recommended complicated regular expressions below. Use
$(?<!.pdf)
instead.– revo
Jan 3 at 12:08
You should not use all the recommended complicated regular expressions below. Use
$(?<!.pdf)
instead.– revo
Jan 3 at 12:08
add a comment |
3 Answers
3
active
oldest
votes
Instead of using regex, you can take the extension of your file and check if it's a pdf.
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext != 'pdf'){
echo "I'm not a pdf";
}
If you prefer using regex
<?php
$file = array("path/file.jpg", "path/file.png", "path/file.pdf");
foreach ($file as &$value) {
preg_match('/^(.(?!.*.pdf$))*$/', $value, $matches);
if(!empty($matches)){
echo " $value is not a pdf";
}
}
https://regex101.com/r/7C7YsR/1
I prefer regex..
– clarkk
Jan 3 at 10:53
add a comment |
If you want to use a regex, this one will work:
^(?!.*.pdf).*$
It simply uses a negative lookahead to assert that the filename doesn't end in .pdf
and then .*
to match everything in the filename.
Demo on regex101
In PHP:
$filenames = array('path/file.jpg','path/file.png','path/file.pdf');
foreach ($filenames as $filename) {
if (preg_match('/^(?!.*.pdf).*$/', $filename)) echo ""$filename" is not a PDF file.n";
}
Output:
"path/file.jpg" is not a PDF file.
"path/file.png" is not a PDF file.
Demo on 3v4l.org
add a comment |
Asserting that something is not present in a regex is often fiddly, because a regex works by looking through the input for things to match.
The approach you've used is a "zero-width negative look-ahead assertion" - it matches anywhere in the string that isn't followed by pdf
, but doesn't "use up" any input. So your regex doesn't work because the rest of it still needs to match, and that is /.$/
, meaning ".
at end of string".
The simplest approach is to look for strings that do end .pdf
, e.g. if ( ! preg_match('/.pdf$/', $file) ) { ... }
.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Instead of using regex, you can take the extension of your file and check if it's a pdf.
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext != 'pdf'){
echo "I'm not a pdf";
}
If you prefer using regex
<?php
$file = array("path/file.jpg", "path/file.png", "path/file.pdf");
foreach ($file as &$value) {
preg_match('/^(.(?!.*.pdf$))*$/', $value, $matches);
if(!empty($matches)){
echo " $value is not a pdf";
}
}
https://regex101.com/r/7C7YsR/1
I prefer regex..
– clarkk
Jan 3 at 10:53
add a comment |
Instead of using regex, you can take the extension of your file and check if it's a pdf.
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext != 'pdf'){
echo "I'm not a pdf";
}
If you prefer using regex
<?php
$file = array("path/file.jpg", "path/file.png", "path/file.pdf");
foreach ($file as &$value) {
preg_match('/^(.(?!.*.pdf$))*$/', $value, $matches);
if(!empty($matches)){
echo " $value is not a pdf";
}
}
https://regex101.com/r/7C7YsR/1
I prefer regex..
– clarkk
Jan 3 at 10:53
add a comment |
Instead of using regex, you can take the extension of your file and check if it's a pdf.
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext != 'pdf'){
echo "I'm not a pdf";
}
If you prefer using regex
<?php
$file = array("path/file.jpg", "path/file.png", "path/file.pdf");
foreach ($file as &$value) {
preg_match('/^(.(?!.*.pdf$))*$/', $value, $matches);
if(!empty($matches)){
echo " $value is not a pdf";
}
}
https://regex101.com/r/7C7YsR/1
Instead of using regex, you can take the extension of your file and check if it's a pdf.
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($ext != 'pdf'){
echo "I'm not a pdf";
}
If you prefer using regex
<?php
$file = array("path/file.jpg", "path/file.png", "path/file.pdf");
foreach ($file as &$value) {
preg_match('/^(.(?!.*.pdf$))*$/', $value, $matches);
if(!empty($matches)){
echo " $value is not a pdf";
}
}
https://regex101.com/r/7C7YsR/1
edited Jan 3 at 11:13
answered Jan 3 at 10:49


executableexecutable
1,9832924
1,9832924
I prefer regex..
– clarkk
Jan 3 at 10:53
add a comment |
I prefer regex..
– clarkk
Jan 3 at 10:53
I prefer regex..
– clarkk
Jan 3 at 10:53
I prefer regex..
– clarkk
Jan 3 at 10:53
add a comment |
If you want to use a regex, this one will work:
^(?!.*.pdf).*$
It simply uses a negative lookahead to assert that the filename doesn't end in .pdf
and then .*
to match everything in the filename.
Demo on regex101
In PHP:
$filenames = array('path/file.jpg','path/file.png','path/file.pdf');
foreach ($filenames as $filename) {
if (preg_match('/^(?!.*.pdf).*$/', $filename)) echo ""$filename" is not a PDF file.n";
}
Output:
"path/file.jpg" is not a PDF file.
"path/file.png" is not a PDF file.
Demo on 3v4l.org
add a comment |
If you want to use a regex, this one will work:
^(?!.*.pdf).*$
It simply uses a negative lookahead to assert that the filename doesn't end in .pdf
and then .*
to match everything in the filename.
Demo on regex101
In PHP:
$filenames = array('path/file.jpg','path/file.png','path/file.pdf');
foreach ($filenames as $filename) {
if (preg_match('/^(?!.*.pdf).*$/', $filename)) echo ""$filename" is not a PDF file.n";
}
Output:
"path/file.jpg" is not a PDF file.
"path/file.png" is not a PDF file.
Demo on 3v4l.org
add a comment |
If you want to use a regex, this one will work:
^(?!.*.pdf).*$
It simply uses a negative lookahead to assert that the filename doesn't end in .pdf
and then .*
to match everything in the filename.
Demo on regex101
In PHP:
$filenames = array('path/file.jpg','path/file.png','path/file.pdf');
foreach ($filenames as $filename) {
if (preg_match('/^(?!.*.pdf).*$/', $filename)) echo ""$filename" is not a PDF file.n";
}
Output:
"path/file.jpg" is not a PDF file.
"path/file.png" is not a PDF file.
Demo on 3v4l.org
If you want to use a regex, this one will work:
^(?!.*.pdf).*$
It simply uses a negative lookahead to assert that the filename doesn't end in .pdf
and then .*
to match everything in the filename.
Demo on regex101
In PHP:
$filenames = array('path/file.jpg','path/file.png','path/file.pdf');
foreach ($filenames as $filename) {
if (preg_match('/^(?!.*.pdf).*$/', $filename)) echo ""$filename" is not a PDF file.n";
}
Output:
"path/file.jpg" is not a PDF file.
"path/file.png" is not a PDF file.
Demo on 3v4l.org
answered Jan 3 at 11:09
NickNick
39.4k132443
39.4k132443
add a comment |
add a comment |
Asserting that something is not present in a regex is often fiddly, because a regex works by looking through the input for things to match.
The approach you've used is a "zero-width negative look-ahead assertion" - it matches anywhere in the string that isn't followed by pdf
, but doesn't "use up" any input. So your regex doesn't work because the rest of it still needs to match, and that is /.$/
, meaning ".
at end of string".
The simplest approach is to look for strings that do end .pdf
, e.g. if ( ! preg_match('/.pdf$/', $file) ) { ... }
.
add a comment |
Asserting that something is not present in a regex is often fiddly, because a regex works by looking through the input for things to match.
The approach you've used is a "zero-width negative look-ahead assertion" - it matches anywhere in the string that isn't followed by pdf
, but doesn't "use up" any input. So your regex doesn't work because the rest of it still needs to match, and that is /.$/
, meaning ".
at end of string".
The simplest approach is to look for strings that do end .pdf
, e.g. if ( ! preg_match('/.pdf$/', $file) ) { ... }
.
add a comment |
Asserting that something is not present in a regex is often fiddly, because a regex works by looking through the input for things to match.
The approach you've used is a "zero-width negative look-ahead assertion" - it matches anywhere in the string that isn't followed by pdf
, but doesn't "use up" any input. So your regex doesn't work because the rest of it still needs to match, and that is /.$/
, meaning ".
at end of string".
The simplest approach is to look for strings that do end .pdf
, e.g. if ( ! preg_match('/.pdf$/', $file) ) { ... }
.
Asserting that something is not present in a regex is often fiddly, because a regex works by looking through the input for things to match.
The approach you've used is a "zero-width negative look-ahead assertion" - it matches anywhere in the string that isn't followed by pdf
, but doesn't "use up" any input. So your regex doesn't work because the rest of it still needs to match, and that is /.$/
, meaning ".
at end of string".
The simplest approach is to look for strings that do end .pdf
, e.g. if ( ! preg_match('/.pdf$/', $file) ) { ... }
.
answered Jan 3 at 11:11


IMSoPIMSoP
48.3k65895
48.3k65895
add a comment |
add a comment |
if the file has a name like
path/pdf_file.png
– executable
Jan 3 at 10:46
match all files except pdf files
– clarkk
Jan 3 at 10:47
.(?!pdf$).+$
– splash58
Jan 3 at 11:05
@splash58 Please avoid posting answers as comments; it makes it harder to find, and impossible to edit, vote on, etc
– IMSoP
Jan 3 at 11:06
You should not use all the recommended complicated regular expressions below. Use
$(?<!.pdf)
instead.– revo
Jan 3 at 12:08