Auto create links in text following a pattern [closed] - javascript

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 to search through the document text and where it finds a pattern of 0000/0, 0000/00 or 0000/000 (where 0 can be any number) it automatically wraps that text in
0000/00
What I found for auto linkers are only when text is a URL, so it doesn't really help with what I need.

A simple regex pattern would do the trick.
text.replace(/(0000\/[0-9]{1,3})/gm, `$1`);
This will look for 0000/ followed by numbers between 0 and 9, 1 to 3 times.

simple regexp approach
document.body.innerHTML = document.body.innerHTML.replace(/(\d{4}\/\d{1,3})/g,
'$1')
Some text 0000/0 and this 1234/56 and that 7777/666

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

Removing specific inputs in any text [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
I'm a complete newbie to programming and I wanna develop a one page-website that removes both numbers and this symbol ==> : from any given sentence.
Let's say you have the following:
(Hey Mr. 11, I'm 18, and I can't wait to turn 20, to own a :)
As you click generate you'd get the following results:
(Hey Mr., I'm, and I can't wait to turn, to own a)
How would you do that?
Here's a dead simple implementation in HTML/JavaScript that uses a regex replacement, to get you started.
document.getElementById('input').onkeyup = function() {
document.getElementById('output').textContent =
this.value.replace(/[0-9:]/g, '');
};
Remove numbers (0-9) and colons (:) from input.
<br>Input: <input type="text" id="input" />
<br>Output: <span id="output"></span>

Select >|< from string between quotes [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 4 years ago.
Improve this question
I have a string like this: *ngIf="thisThing > 0"
Using RegEx, I'd like to select/return ONLY the > or in some cases, <.
I have the following expression: (?<=")(?:.*?)(<|>)(?:.*?)(?=") but this still selects everything inside the quotes. I only want to match that >.
I've been testing it here: https://regex101.com/r/4KPfbT/1
I guess you're over-complexifying it. Why not this way:
\w*=".*([<>]).*"
It works, take a look:
console.log('*ngIf="thisThing > 0"'.match(/w*=".*([<>]).*"/)[1])
console.log('whatever="otherThing < 999"'.match(/w*=".*([<>]).*"/)[1])

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