I have a text of type:
You have a new code: 12345678 Validity of the code: 20 minutes
what regular expression would cut only the numbers between words code:
and Validity
? I need to extract the code. Thanks in advance!
PS It should work in JavaScript
Use \\d+
, don't use the g
lobal flag. It will grab the first sequence of digits it encounters, which should be the code.
/\\d+/
should do it. If you just use string.exec(/\\d+/)
you'll get back just the first match.
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.