Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Can any one help me to create regular expression using match function split based on ":" string to fixed length array of 9. values has to be filled from end. if the string contains 2 or 3 remaining has to be filled as blank.
some thing like following:
var matchedString = new RegExp(^(?:\xAB([^\xAB\xBB:={}]+)\xBB)?([#|+|-|~])?([/])?([^\xAB\xBB:={}]+)?(?:: ([^\xAB\xBB:={}]+))$);
var arr = matchedString.exec(1dsds:2dsds)
Posted

1 solution

You made it extremely complicated...
First of all - there is no such thing in JavaScript s fixed size array. What you can do in the context of splitting is not to exceed the maximum size...
In JavaScript split function can get the separator as RegEx (even in your case it is a simple char and for that RegEx is a waste!) and can limit the number of elements it returns...
JavaScript
var str = '1dsds:2dsds';
var ar = str.split(/:/, 9); // or better not to use RegEx at all - str.split(':', 0);

See split in JavaScript here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900