简体   繁体   中英

Regex match only first occurrence after key string

Regex:

(?<=KEY.{1,99})([0-9]*)

Example text:

test 74488 hdhd2 768 788 KEY bla gjjjcrs 6448. gfudj778. 2 bla 77545 77890 7754

Desired result:

6448

I need only first match of digits group after KEY. Can I make regexp stop searching after first digit group occurrence to reduce CPU load? Or I don't need it?

You might want to try this one :

KEY.*?(\d+)

Demo here .

Use: (.*) (KEY) ([^0-9]*)(\\d+)

Demo

If you want to match only those digits after KEY: (?:.* KEY) (?:[^0-9]*)(\\d+)

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