Jo'natish uchun muntazam ifoda

Quyidagi qatorni oldim:

"url("http://localhost/image/user/temp/n9cec42c939ab461cac7852c267413b1b.jpg")"

Javascript muntazam ifodasi yordamida fayl nomini qanday qilib olishim mumkin?

Men [^ /] + $ ni sinab ko'rdim, lekin oxirida ") ushlaydi.

Rahmat.

0

4 javoblar

[^/]+"\)$

sizning namunangizda ishlaydi. Agar siz keyinchalik bunday bo'lmasangiz, iltimos, savolingizga batafsil ma'lumot bering.

0
qo'shib qo'ydi

Siz yozgan narsalarga juda yaqin

/[^\/]+(?=\"\)$)/

misol uchun

/[^\/]+(?=\"\)$)/.exec(s)

bu erda s sizning namunangiz qatori to'g'ri fayl nomini qaytaradi.

(Izoh: muntazam iboralar bilan (? = ...) formasi o'yinni kuzatib turishi kerak, lekin bu o'yinning bir qismi hisoblanmasligi kerak).

0
qo'shib qo'ydi

split on backslash, pop to get the last result, and remove the ")

'url("http://localhost/image/user/temp/n9cec42c939ab461cac7852c267413b1b.jpg")'.split('/').pop().replace('\")', '')

Misol

Yoki agar RegExp faqat sizning narsa:

var url = 'url("http://localhost/image/user/temp/n9cec42c939ab461cac7852c267413b1b.jpg")'; 
url.match(/.+\/(.+)\"\)/)[1];//file name
0
qo'shib qo'ydi

Regexp yordamida siz quyidagilarni foydalanishingiz mumkin:

'url("http://localhost/image/user/temp/n9cec42c939ab461cac7852c267413b1b.jpg")'.match(/\/([\d\w]+\.[\w]+)/)[1]

fayl nomini a-z + 0-9 dan va uchta belgilar kengaytmasidan iborat deb hisoblaymiz

0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb