Javascript determines whether a string is an image path

javascript determines whether a string is an image path?

I have an uncertain string: it could be: http://www.baidu.com (for url address path)
or it could be: https://img.codeshelper.com/upload/img/2021/02/28/pk4nm4innyg1209.png (for picture)

how can I tell if this string is a picture?

Feb.28,2021

think of webpack's feelings about the packaging of pictures.
regular


const PICTURE_EXPRESSION = /\.(png|jpe?g|gif|svg)(\?.*)?$/
const picReg = new RegExp (PICTURE_EXPRESSION)
url
const URL_REGULAR_EXPRESSION = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/
const objExp = new RegExp(URL_REGULAR_EXPRESSION)
~

alas, directly intercept the format to judge

var url =' http://www.baidu.com';
var sub = url.substring ('.));
if (sub = '.com' | | sub = '.cn') {
console.log ('Yes, this is the URL')
} else {
console.log ('Yes, this is a picture')
}


doesn't seem to be a picture path, but it can also be a picture. For a URL, a picture is just an output. It has nothing to do with the path


wrote a rule, which should be good:

function check_is_img(url) {
  return (url.match(/\.(jpeg|jpg|gif|png)$/) != null)
}



url.split('.')[1]=='png'||url.split('.')[1]=='jpg'

add other pictures yourself

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3765f-2b5da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3765f-2b5da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?