regex - How can I extract a number from a string in JavaScript?

  Рет қаралды 117

Code Samples

Code Samples

Ай бұрын

I have a string in JavaScript (e.g., #box2), and I just want the 2 from it.
I tried:
var thestring = $(this).attr('href');
var thenum = thestring.replace(/(^.+)(\w\d+\w)(.+$)/i, '$2');
alert(thenum);
It still returns #box2 in the alert. How can I get it to work?
It needs to accommodate for any length number attached on the end.

Пікірлер: 1
@calvinlucian387
@calvinlucian387 Ай бұрын
If AI has learnt how to generate Regex then we're surely out of jobs for humans.
The TRUTH About Golang Backend Frameworks
6:31
Melkey
Рет қаралды 93 М.
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 2,3 МЛН
Learn React Hooks: useMemo - Simply Explained!
13:41
Cosden Solutions
Рет қаралды 72 М.
the new PS4 jailbreak is sort of hilarious
12:21
Low Level Learning
Рет қаралды 328 М.
How to Format Dates with Vanilla JavaScript
10:51
Coding in Public
Рет қаралды 6 М.
Времена жизни в Rust
19:29
Bitωise
Рет қаралды 1,7 М.
ChatGPT Can Now Talk Like a Human [Latest Updates]
22:21
ColdFusion
Рет қаралды 141 М.
My Initial Impresson Of Go
12:39
TheVimeagen
Рет қаралды 11 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 127 М.
Learn JavaScript DATE objects in 8 minutes! 📅
8:02
Bro Code
Рет қаралды 10 М.
Responsive Typography with CSS Clamp
8:37
Tom Is Loading
Рет қаралды 33 М.
Learn CSS Animations In 20 Minutes - For Beginners
21:22
Slaying The Dragon
Рет қаралды 919 М.
Best transport for daughter #shorts by Tsuriki Show
0:12
Tsuriki Show
Рет қаралды 3,2 МЛН
П*ВО ДЛЯ СОБАК
0:47
Натали Макколи
Рет қаралды 2,1 МЛН
Эта невеста помогла бездомным❤️
0:32
Narezchik Lombard
Рет қаралды 6 МЛН