I am struggling with javascript regex (regex in general actually).
I have a string of text looks like this,
wall_treatment/S3/COOL_NEUTRAL/MMC_Walls_FC_S1_COOL_NEUTRAL_00000.png
In the string above I want to look for a string that matchesSn (where n is a number). Is this possible?
1 Answer1
var data="wall_treatment/S3/COOL_NEUTRAL/MMC_Walls_FC_S1_COOL_NEUTRAL_00000.png";console.log(/S\d/.exec(data)[0]);will give you the first matchS3. If you want all the instances, you can do
console.log(data.match(/S\d/g));will give all the matches and in this case it is
[ 'S3', 'S1' ] Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
