javascriptregex

How to match and extract a regular expression pattern?


I have a string like so - SampleReleaseFY20Q3.STRY0122544.Developer.SDLCRework.6

Now, I would like to extract the pattern STRY******* and store it in a variable. So in this case, I would like to extract STRY0122544 and store it in a variable.

Any help with this is appreciated!

Thanks, Raskill


Solution

  • We can use string match here:

    var input = "SampleReleaseFY20Q3.STRY0122544.Developer.SDLCRework.6";
    var output = input.match(/STRY\d+/)[0];
    console.log(output);