2

I need to adjust a regex I am using for a file name. currently the file is structured 02-2015 VRF WE32.pdf the regex splits up the string into 3 pieces by the spaces. This works fine. the result is

02-2015
VRF
WE32

But now i need to split the string into 4 pieces. the 4th being the digits in the 'WE32'. so it needs to look like this

02-2015
VRF
WE
32

Here is what I am using, including some screenshots

var matchesPip = file.name.match(/^\d+\D\d+\s*(\S*\s*)(\S*)/i);
var matchesLoc = file.name.match(/^\d+\D\d+\s*?(\S*)\s*(\S*?)\./i);
var matchesLocCode = file.name.match(NEED HELP HERE);
    $scope.pip = $scope.pipeLookup[matchesPip[1]];
    $scope.loc = $scope.locationLookup[matchesLoc[2]];
    $scope.locCode = $scope.locationCodeLookup[matchesLocCode[3]];

pic1 pic2 pic3

2 Answers 2

2

Looks like you just need to provide number matching group (\d+) after non-spaces one:

^(\d+\D\d+)\s*?(\S*)\s*(\S*?)(\d+)\.

Test: https://regex101.com/r/bP7oF2/1

Sign up to request clarification or add additional context in comments.

Comments

1

Why don't you use split instead ? For example

var fn = '02-2015 VRF WE32.pdf';
var chunks = fn.split(' ');
var moreChunks = chunks[2].split('.');
alert (moreChunks[0]);

will give you WE32

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.