• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Read a string and detect the first 8 numbers group

Enthusiast ,
Jul 08, 2011 Jul 08, 2011

Copy link to clipboard

Copied

I want to pick a string information inside of a bigger string (file name or folder name)

The string I want to pick is a 8 digit number (next to each other) and it can be some where in the middle of  the big string.

For example:

Big string A:

_v_10097822-YVES.SAINT.LAURENT.273456YOD02.4176.Silk.15113

Big string B:

_v_nkld3sgrf10097822-YVES.SAINT.LAURENT.273456YOD02.4176.Silk.15113

I want to read always the 10097822

How can I do that with code in a function that returns the number I want?

TOPICS
Actions and scripting

Views

320

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jul 08, 2011 Jul 08, 2011

You could try this..


var numberFromString = getNumbers("_v_nkld3sgrf10097822-YVES.SAINT.LAURENT.273456YOD02.4176.Silk.15113");
alert(numberFromString);

function getNumbers(str){
return str.match(/\d{8}/);
}

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jul 08, 2011 Jul 08, 2011

Copy link to clipboard

Copied

You could try this..


var numberFromString = getNumbers("_v_nkld3sgrf10097822-YVES.SAINT.LAURENT.273456YOD02.4176.Silk.15113");
alert(numberFromString);

function getNumbers(str){
return str.match(/\d{8}/);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 08, 2011 Jul 08, 2011

Copy link to clipboard

Copied

LATEST

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines