Split in javascript based on regex [closed] - javascript

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 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
Regex needed that will split string based on following criteria
I need to split string based on regex in javascript. The format of the string is as follows 'publication_or_portfolio_links.0.link'
I need to split based on '.index.' (note dot before and after the inex) i.e. the result should be 'publication_or_portfolio_links' and 'link' i.e. '.0.' has been removed.
I would be thankful if some help me.

\.\d+\.
Demo:
const str = 'publication_or_portfolio_links.0.link';
const res = str.split(/\.\d+\./gm)
console.log(res)
regex101 explanation:

Related

How to remove specific characters in a string that changes based on request? [closed]

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 6 months ago.
Improve this question
I have a string that looks like "{`index`:`20`,`value`:`RA`}<1", and I want it to become "`RA`<1". I don't think the replace function is sufficient as the index and value changes based on what I enter. Is there a way to do that?
assuming the required string is everything after the last :, except for the }, the original string can be sliced and edited as follows:
const string = "{`index`:`20`,`value`:`RA`}<1";
let newString = string.slice(string.lastIndexOf(":")+1).split("}").join("");
console.log(newString);
This will always append everything after the final } to everthing before it but after the last :, regardless of the earlier content.

How to separate a string into a sentence without a proper patern [closed]

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.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
I have a data that looks like this
Huawei Y7P Art-L28 (4/64gb) (AAAAAAAAAAAAAA) EXP:02/19/2020
Huawei Y9 prime 2019 (BBBBBBBBBBBBBBB) EXP:07/17/2019
Oppo A31 4gb/128gb (CCCCCCCCCCCCCCC)
Vivo Y15 5000mah 4GB/64GB (1901) (DDDDDDDDDDDDDDD) EXP:06/14/2019
And the I want to get this data
AAAAAAAAAAAAAA
BBBBBBBBBBBBBBB
CCCCCCCCCCCCCCC
DDDDDDDDDDDDDDD
Basically what I want to happen is to extract the data from the set of word but my problem here is that its very unpredictable. It has no pattern at all so its hard to separate the string.
Assuming that you need a substring in last parenthesis:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(column, '(', -1), ')', 1)
FROM source_table

How to Remove two consecutive double quotes from array after split [closed]

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 have a requirement where i will get the input from the user. He can enter
"features1,feature2",feature3,"feature4"
something like this. I'm using this
let arr: any = message.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/)
to split the string and i'm getting result like
[""feature1,feature2"","feature3",""feature4""]
but i want the result like this
["feature1,feature2","feature3","feature4"]
I don't thing what you're trying to achieve is possible only using split function.
After you split, loop over the error and replace " with `` (empty).
const message = `"features1,feature2",feature3,"feature4"`;
let arr = message.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);
arr = arr.map(el=>el.replace(/"/g,''));
console.log(arr);

Javascript Split string into multi-dimensional array [closed]

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'm looking to split a string into a javascript multi-dimensional array. Assistance or pointers would he hugely appreciated.
String consists of 3 fields - comma delimiter for each field, and # delimiter for each record
Data/String:
Big Ben,www.myurl.com,2020-10-03#Buckingham Palace,www.myurl2.com,2020-15-03#
thank you in advance.
The following gets what you're after.
let string = 'Big Ben,www.myurl.com,2020-10-03#Buckingham Palace,www.myurl2.com,2020-15-03#';
let result = string.split('#').filter(function(el) {return el.length !== 0}).map(row => {
return row.split(',');
});
console.log(result);

Email Regex for Javascript Which not start with Number [closed]

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
^[a-zA-Z]\w+#[a-zA-Z_]+?\.[a-zA-Z]{2,4}$
i had tried this regex for email but it allow following cases
123#mail.com
example.mail#mail.com
Here is the code which searches for the number at the start.
If number is matched it prints message in console.
let regex = /^[0-9]/;
let object = [{email:'123#mail.com'},{email:'example.mail#mail.com'}];
for(let i =0;i<object.length;i++){
if(object[i].email.match(regex)){
console.log('E-mail ',object[i].email,' is not valid.')
}
}
This is the used regex: ^[0-9]

Categories

Resources