0

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?

thefourtheye's user avatar
thefourtheye
241k53 gold badges466 silver badges505 bronze badges
askedJan 7, 2014 at 12:48
Udders's user avatar
2
  • Could it beS12,S01 or evenS001003 ?CommentedJan 7, 2014 at 12:57
  • Could you explain why you need that? What are you doing with this path?CommentedJan 7, 2014 at 13:15

1 Answer1

2
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' ]
answeredJan 7, 2014 at 12:50
thefourtheye's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.