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 cannot understand the function used below that just splits a string on '.'.
Could you help me understand why it uses the extra replace statements?
function dotSplit (str) {
return str.replace(/\1/g, '\u0002LITERAL\\1LITERAL\u0002')
.replace(/\\\./g, '\u0001')
.split(/\./).map(function (part) {
return part.replace(/\1/g, '\\.')
.replace(/\2LITERAL\\1LITERAL\2/g, '\u0001')
})
}
Here, \1 means to match the character whose octal representation in Latin-1 encoding is 1. That character is SOH, or the start of heading character. What it does above is replace all occurrences of that with \u0002LITERAL\\1LITERAL\u0002, where \u2002 stands for the character STX(Start of text).
You can try it here:
https://regex101.com/r/n9LaJY/1
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 3 months ago.
Improve this question
I have a string with HTML in between. What I want to achieve is add a space in between after every 2nd character.
For example for input like below -
'<span>234567</span><span>34526754</span>'
'<span>23 45 67</span><span>34 52 67 54</span>'
How can I achieve this in JavaScript?
let str = '<span>234567</span><span>34526754</span>'
str.match(/(?<=\<span>).*?(?=<\/span>)/g).forEach(s=>{
str = str.replace(s, s.match(/.{2}/g).join(' '))
})
console.log(str)
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 want to write a regular expression which would look like for ex: H005-2007-652764
First char should start with `H`
5th and 10th char should be `-`
Remaining all should be digits
Your requirements are perhaps not totally complete, but if I assume that you only want six digit characters at the end, something like the regex /H\d{3}-\d{4}-\d{6}/ would work. You can see it working here or in the snippet below:
const text = 'nonsense nonsense lorem ipsum H005-2007-652764 and then more nonsense';
const regex = /H\d{3}-\d{4}-\d{6}/;
console.log(text.match(regex));
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
Team
I would like to have a RegEx (in javascript) to validate below conditions.
Value should have atleast 3 chars
First and last char should be single quote.
please advice how the regex should be?
Thanks in advance.
If you mean three chars total:
const regex = /'.+'/;
If you mean three chars plus quotes:
const regex = /'.{3,}'/;
More info:
https://javascript.info/regexp-quantifiers
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
consider a string which has question marks, numbers , letters.
check for three question marks between two numbers where in when adding those two numbers it should be 10.In that case return it as string true or else string false.example: "bdhfr6???4hfyrt5???eee5".Above example return string true because between 6 and 4 there are 3 question marks and between 5 and 5 exactly 3 question marks
or else false
I leave the refactoring of regex on you, but this is something you can do using String.prototype.match.
function checkStr(str) {
let match = str.match(/(\d)\?{3}(\d)/);
return match && +match[1] + +match[2] === 10;
}
let out = checkStr('bdhfr6???3hfyrt5???eee5');
console.log(out)
out = checkStr('bdhfr6???4hfyrt5???eee5');
console.log(out)
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 don't no how regex works. but I have a url like:
http://localhost/BetaLeren/public/dashboard/general/video.php?video=13&time=19
but I want it that way:
http://localhost/BetaLeren/public/dashboard/general/video.php?video=13
How I can i do that with refex?
or is there a better way?
If you'll always have video= followed by time=, you could use the following regex:
const link = 'http://localhost/BetaLeren/public/dashboard/general/video.php?video=13&time=19';
const updatedLink = link.match(/^.+video=\d+/)[0];
console.log(updatedLink);
^ represents the beginning of the string.
.+ represents any character 1 or more times.
\d+ represents any digit 1 or more times.