regexp - How to "match but not contain" a certain condition with JavaScript's regular expression?
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:28:12
0
2
863
/images/img2.jpg" alt="" class="img"

As shown in the above code, there are two "img" words. I want to match the "img" in the first "img2", but does not include "2". I don't know how to achieve it.

If /img[0-9]/ is used, "2" is also included. Is there any way to match numbers followed by numbers, but the result does not include numbers?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
左手右手慢动作

/(img)d/.exec('/images/img2.jpg" alt="" class="img"')[1]
match img and have numbers after it, the specific number of numbers depends on your match, and finally take it out The data in the matching group is img, grouped by parentheses

.
女神的闺蜜爱上我
\bimg+(?=\d)

Thanks for the comment. It turns out that this is a suitable situation for using zero-width assertions. I looked up the information and wrote one.
The plus sign is preceded by the result to be matched ("img"), followed by the selection condition (meaning that img must contain a number), this solves the problem~
O(∩_∩)O~~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!