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 last year.
The community is reviewing whether to reopen this question as of 12 months ago.
Improve this question
I am trying to write a regex to extract the items in the text below that start with the # and ends with )
const bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)";
So basically, will want an array that looks like:
["#[DataStructures](topic_DataStructures)", "#[Algorithms](topic_Algorithms)", "#[Make or Mar](topic_Make or Mar)"]
Using string match() we can try:
var bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)";
var matches = bodyOfText.match(/#\[.*?\]\(.*?\)/g);
console.log(matches);
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 10 months ago.
Improve this question
i am dealing with strings in vuejs. Now I have 4 url strings:
https://web-sand.com/product/slug/apple-iphone-13
https://web-sand.com/product/slug/samsung-galaxy
https://web-sand.com/product/slug/xiaomi-red
https://web-sand.com/product/slug/apple-ipad
Now I want to process to get the final string. Since my string is not fixed length using fixed ways is not efficient.
Result I want to get :
apple-iphone-13
samsung-galaxy
xiaomi-red
apple-ipad
Everyone please give me any comments, thanks.
You can use:
function getStr(str) {
return str.split('\/').pop()
}
Here:
input.split("\n").map(line => line.split("/").pop())
[
'https://web-sand.com/product/slug/apple-iphone-13',
'https://web-sand.com/product/slug/samsung-galaxy',
'https://web-sand.com/product/slug/xiaomi-red',
'https://web-sand.com/product/slug/apple-ipad'
].map(item => item.split('/').pop())
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 1 year ago.
Improve this question
With the following array of strings in javascript, is there a way to use the .filter to filter by the first word?
['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two']
For example to .filter(x = 'Desk_*')
['Desk_One', 'Desk_Two', 'Desk_Three']
Maybe this needs to be a regex
You can use startsWith() function like this:
let array = ['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two'];
let result = array.filter((item)=>item.startsWith(array[0].split('_')[0]));
console.log(result)
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
I am a beginner to javascript and I am confused on how to split a string which is separated by line breaks, into a 2d array. Here is the string. The numbers represent something that I need to make the code function, so excuse that:
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
20000000010000000000000100000001000001000001000000000001000000000100010000010000010000000100001
11011111110111111111110101110101011101011101011101111101111111010101011101010101110101111100101
11000000010000010001010001000100010001000100000101000100000100010101000101010100000100000000101
11011111011111010101011111011111011111011111111101010111110101110101110101110111111111111111101
11010001000001000101000001010001010000010000010001010001000101010100010001000100010001000100001
11010101111101111101110101010101010111110111010111011101011101010111011111011101010101011100101
11010100000000000100010101000100010000010001000101010001000001010100010001010001000100010000101
11010111111111110111010101111111011111011101111101010111111111010101010101010101111111110111101
11010100000000000001010100000001000001000100010000010000010000000001010100010101000000000100001
11010111011111111101010111011111110111110111011111011111010111111111010111110111011111111111111
11010001000100010001010101010000010100010001000001010001000101000001010000000100010000000000001
11011101110101010111010101010101010101010111111101011101111101011101110111111101110111111111101
11000101000101010001010001000101010001000100000001000001000001010100000100000001000100000100001
11011101111101011111011111111101111111111101111111111101110101010111111101111101011101110101111
11010001000001010000010000000100000100000001000001000100000101010000000100010001000101000100001
11010111011111010111110111110111110101111111010111010111111101010111110111011111110111011111001
11010001010001000100000100000000000101000000010001010001000001000101000101000100010001000100001
11011101011101111111110111111111110101011111111101011101011111111101011101110101011101110101001
11010101000100000000010000000100000101000000000101000100000000010001000100010001000000000101001
11010101110101111111011111110111111101111111111101110101111101110101110111011111111111111101001
11000100010100010001000000000100000001000000000100010101000101000101000100010100000001000001001
11110101110100010111111111011101111111011111110101110101010111011101011101010101011101011111111
11000101000100010100000001010001000000010001000101000101010000000100000001010001000101000000001
11011101011101110101011111010111011111110111011101011101011111111111111111010111110111111111001
11000100010001000101000001010001000000010100010100000001010001000001000001010100000100010001001
11110111110101110101111101011101111111010101110101111111010111011101010111010101110101010101001
11000100010100010100010101000100000001000101000001010001000100010101010001010100010101010100001
11011101010111010111010101110111111101110101111101010101011101110101111101011111010101010111111
11000101000100010000010100000000000100000100000100010100010001010001000100000000010101010000001
11110101111101011111010111111111111111111101110111010111110111010111010111111111110101011111001
11010100010001010001000001010000000001000100010100010001010100010100010000000000010101000000001
11010111010111110101111101010101111101010111110101111101010101110101011111111111011101111111001
11000100010100000101000000010101000100010000010100010000010101000101000001000001000100010001001
11011111110101111111011111110111010111111111010111110111110101011111111101011101110101010101001
11000000000100010000000100010000010100010001010000000100000101000000010001000100000101000101001
11111111110111011111011101010111110101010101011111110101111101111111010111111111011111011101001
11000000000101000001010001010100000101010100010000010100010001000000010000000001010001010001001
11011111111101111101110111011101111101010111110111011111010111011111111111111101010101110111001
11000000000000000100000100000001000001000000000100000000010000000000000000000001000100000100003
Hey buddy I'm also new but I actually have an idea. You can try this:
a.split("\n");
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 2 years ago.
Improve this question
I'm trying to replace string
'null-null-1234' to '***-**-1234'
const p = 'null-null-1234';
const regex = /null/gi;
console.log(p.replace(regex, '***'));
Output => "***-***-1234" NOT AS EXPECTED
p.replace(/null-null/, '***-**')
I think what you actually want to do is to make a distinction between first and second values.
Hence, you probably need 2 regexes.
p.replace(/^null/, '***').replace(/-null-/, '-**-')
The first one will replace the null in first position (if any) by 3 stars, and the second replace will replace a null in the middle (if any) by 2 stars.
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 8 years ago.
Improve this question
how would I check for string
<something> in var string = "some chars <something> somechars"
You can use String.match():
var res = string.match(/<something>/g); // ["<something>"]
If there is no match, the value of res will be null. See example on JSFiddle.