Regex with substitution around a number [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 5 years ago.
Improve this question
I have a problem in some substitution in javascript (HTML).
I need to substitute ONLY the tags around every number, e.g.
<1>
become:
<sub>1</sub>
or
<20>
become
<sub>20</sub>
etc.
How can I do?
Thank you so much!

You can use replace and regex with groups to achieve this:
var text = '<1>blabla<20>';
var newText = text.replace(/<(\d+)>/g, '<sub>$1</sub>');
console.log(newText);

Related

extracting letters from an array of strings [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 an array of strings denoting variants of shirts in my store.
Here is an example string:
Apparel-DTG-Tshirt-District-DT6000-M-Black-Mens-CF-20200304113232677
All of the strings share same structure and the rule that I need to implement is, extract what's in between 5th and 6th occurrence of - (dash). In this particular case this is M.
How do I do that?
This would help you. The first capturing group will be the value between fifth and sixth dash:
https://regex101.com/r/UlQBqy/2
const re = /^(?:[^-]*-){5}(.*?)(?=-)/
console.log("Apparel-DTG-Tshirt-District-DT6000-M-Black-Mens-CF-20200304113232677".match(re)[1])

Regular expression (Regex) to allow only number or specific character with number at a time [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 3 years ago.
Improve this question
I have a requirement to allow any digits with only one character (either w or d or W or D) at a time with no sequence.
For example: 2 or 2w or 222W or 2d or 222D
(not like 2wd, 55dw, 2w5d, 2w5w, 2D5D etc)
Could you please provide solution on this. Thanks.
Try the following:
^\d+[wdWD]?$
Try it out:https://regex101.com/r/sYqjTi/1
If you don't want it to match just 2, remove the ?, it will make the last letter required.
This regex should work both on Java and JavaScript.

Regex match after semicolon and separated comma [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 have a string like
Menu: apple, orange-juice, bananas
I want to use REGEX to match only apple orange-juice bananas
I have tried to search Google and regex101.com for help but still no any idea.
I would appreciate any help! Thank you
You can do the following in javascript :
var string = "Menu: apple, orange-juice, bananas";
console.log(string.replace(/Menu: |\,/g, ""))
Regex101 : https://regex101.com/r/N0AfW7/1

Are (/\s{2,}/) and (/\s{2,''}/) the same? If not then please explain the difference [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 8 years ago.
Improve this question
I just wanted to know difference between (/\s{2,}/) and (/\s{2,''}/) regular expressions?
Please explain with an example.
Are \s{2,} and \s{2,''} the same?
NO, both are different.
\s{2,} --> Two or more spaces.
\s{2,''} --> Matches a white space character[\r\n\t\f] and literal {2,''}

what does document.createElement("_") do in javascript [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 8 years ago.
Improve this question
Please have a look at https://github.com/eligrey/classList.js/blob/master/classList.js :
if ("document" in self && !("classList" in document.createElement("_"))) {
//...
}
What is the purpose of document.createElement("_")? I know it creates an html element, but why use _ instead of an html element name?
It creates an element with the tag <_>. I see no reasonable purpose to this.

Categories

Resources