Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to tokenize a string representing an item in inventory in javascript getting words and numbers, for example:
Given the string 'Plane Engine 50x60' the tokens should be ['Plane','Engine','50','x','60']
Given the string 'Car wheel 220v' the tokens should be ['Car','wheel','220','v']
The solution could be a RegExp or a Javascript Algorithm
All the items have that kind of names come has measures like 20x30 and others have electronic info such as 220v. The thing I need to do is split like the examples above.
Thanks
We can split by groups of either numbers or letters and then filter out the empty strings or spaces.
'Car wheel 220v'.split(/([0-9]+|[a-zA-Z]+)/).filter(token => (token.match(/[a-zA-Z0-9]/)))
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Im working on a simple program and im trying to put user input in it and i want to know if theres an easy way of doing that.
You can split on the comma and use map along with the unary plus operator to convert each element to a number.
str.split(",").map(a=>+a);
const str = "1,2,3,4";
const arr = str.split(",").map(a=>+a);
console.log(arr);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
My goal is to pull chunks of 0's or 1's from a binary string. Using regex.match to look for patterns pulls out all chunks and loses order. I need to be able to pass any length of binary to it. How can I correctly pull out chunks so that '10011000001' -> '1', '00', '11', '00000', '1'?
I can only think to run a loop to count the number of changes from 0 to 1 then run alternating regex.match() on it, but that's certainly inefficient.
You could look for a digit and look for more of the same group.
var string = '10011000001',
parts = string.match(/([01])\1*/g);
console.log(parts);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a simple Regex to match 'der' - /der/g
I need the context around the match. Is there any way to build the regex that way? Thank you in advance.
If you want to match the context plus the search string, simply add the optional range before and after the searched string: .{0,5}der.{0,5}
If you want to get the context only, you have to fetch it separately: (.{0,5})der(.{0,5})
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Friends in my ionic application API return data's are in Spanish language, I want to implement local search(sub string matching) in these data. Unfortunately accent/diacritics are does not match with normal character
Eg. 'María', here 'í' is different from normal 'i'
When I search using key word 'maria' i don't get the result.
How can I check 'í' is equal to 'i' and other characters.
Based on the answer of this question: Remove accents/diacritics in a string in JavaScript
I don't know how you are doing your search, but it's normal that you don't get any result with í and i, they don't have the same ASCII code.
What you can do during your search is replacing temporary all accents and diacritics in your search text and in your data text.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
If i have Full name coming as an input from the user without any spaces, how would i be able to differentiate first name and last name. The Full name for the input could be any name (generic input).
In the general case, you can't.
There are some things you might be able to do depending on what you receive. For instance, if you get "JohnSmith", then you can probably split them on the first uppercase character that isn't the first character of the string, but that could break in all kinds of ways —"ManueldelaVega", for instance, or "JOHNSMITH" or "mohammedibnabdul".
So again: In the general case, you can't.