This question already has answers here:
Allow "/" forward slash in regular expression
(2 answers)
Closed 3 years ago.
Visual Studio Code is reporting a syntax issue with this regex in javascript:
let regex;
regex = /^https:\/\/[^\/]+/[A-Za-z]+-[\d\D]{4}-Report$/g;
Specifically, squiggly red underline beneath \d and {
Before I start ripping out extensions, does anyone see anything obvious?
You have a missing escaping backslash here:
/^https:\/\/[^\/]+/[A-Za-z]+-[\d\D]{4}-Report$/g
^
So it should be:
/^https:\/\/[^\/]+\/[A-Za-z]+-[\d\D]{4}-Report$/g
Related
This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
I'm not sure what the code below means. I know how to use match, but I'm not sure on what the brackets and "^" signs mean. Is there a website to where I can understand what all you can do with match?
var imagesURL;
imagesURL = html.match(/CapImg[^"']*/g);
match is usually used along with RegExp to search through a data for a particular value or pattern of values. ..
You should rather go and read about JavaScript RegExp (or Regular Expression).
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
This question already has answers here:
Match only unicode letters
(3 answers)
Closed 4 years ago.
I have this PHP regex:
/^[\p{L}\p{M}]+[\p{L}\p{M}\-\s]*$/u
and I want to convert it to jQuery. I tried multiple solutions that I found online, but nothing really worked. I tried using
new RegExp("/^[\p{L}\p{M}]+[\p{L}\p{M}\-\s]*$/u");
but that didn't help.
This is because \p{L} and \p{M} don't exist in the JavaScript RegEx engine. This answer provides solutions for matching Unicode categories: https://stackoverflow.com/a/26659285/1920035
This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
What does this `…${…}…` code in the node docs mean? [duplicate]
(1 answer)
Closed 5 years ago.
I'm a bit of a beginner still and keep coming across this in code:
${Math.round(newProps.percent)}% surrounded by backticks
or
${currentBillingStartDate} surrounded by backticks and not using the percent.
I'd like to understand when it should be used and why.
The percent sign is just a character that is meant to be interpolated with the expression inside the ${variable}. The result would be a string that looks like "55%"
This question already has answers here:
What is the JavaScript string newline character?
(15 answers)
Closed 6 years ago.
Can someone please explain to me what is a Line Terminator? I have trouble searching it online. It may be slightly irrelevant to the question but I would just like to know.
A line terminator is OS specific. This doesn't have anything to do with JavaScript. On windows a line is terminated by the control character sequence \r\n, On UNIX like systems, it is \n.
Recall that control characters aren't printable characters, so the \r and \n is conceptual, but usually they're put in string literals to represent the control character.
This question already has answers here:
JSLint "insecure ^" in regular expression
(3 answers)
JSLint reports "Insecure ^" for my regex -- what does that mean?
(3 answers)
Closed 8 years ago.
jslint detects my following code as not secure:
/([^\n]+)([\n\s]*)/g
Later I learned there is a lint option:
". and [^...] in /RegExp/"
which you can find over here
Why is it not secure?
The problem is with the [^...] character you're allowing almost anything in your regex and jshint detects a security risk.
This is what jslint docs says about [^...]:
true if . and [^...] should be allowed in RegExp literals. They match
more material than might be expected, allowing attackers to confuse
applications. These forms should not be used when validating in secure
applications.