简体   繁体   中英

Match number between characters

Here is some examples 158811_ 23 .jpg 151_ 188 .gif

How to match the number between _ and .jpg ?

This fairly simple regular expression should match the number you need as the first group:

[0-9]*_([0-9])*\.(?:jpg|gif)

It works for both .jpg and .gif files, since you used both in your examples.

使用它来将您的数字分成 $1 gif 等在 $2 中的组

_(\\d+)\\.(gif|jpg)

If you want to match the numbers between _ and .jpg but exclude the _ and .jpg then use:

(?<=\\_)[0-9]+(?=\\.jpg)

(?<=\\\\_) is called a lookbehind . Anything after the _ except the _

(?=\\\\.jpg) is called a lookahead . Anything before the .jpg excluding the .jpg

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