DEV Community

Discussion on: October 8th, 2021: What did you learn this week?

Collapse
 
derekenos profile image
Derek Enos • Edited

I learned that you can use a regular expression that specifies the g flag with exec()to perform iterative matching in JavaScript :

>> const regex = /./g
>> const s = "What is happening?"
>> regex.exec(s)
Array [ "W" ]
>> regex.exec(s)
Array [ "h" ]
>> regex.exec(s)
Array [ "a" ]
>> regex.exec(s)
Array [ "t" ]
...
>> regex.exec(s)
null
>> regex.exec(s)
Array [ "W" ]
Enter fullscreen mode Exit fullscreen mode

Collapse
 
nickytonline profile image
Nick Taylor

Nice!

Nice