Why is [^...] in /RegExp/ not secure? [duplicate] - javascript

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.

Related

How to show a string as its unicode code points? [duplicate]

This question already has answers here:
Need to escape non-ASCII characters in JavaScript
(4 answers)
Javascript, convert unicode string to Javascript escape?
(6 answers)
Closed 1 year ago.
Just from a browser developer console or Node.js repl, what's an easy way to transcribe a string as its unicode representation? For example I can input '\u0048\u0065\u006C\u006C\u006F' and the repl will show me 'Hello'
> '\u0048\u0065\u006C\u006C\u006F'
"Hello"
How can I reverse this?
> something('Hello')
"\u0048\u0065\u006C\u006C\u006F"
For example. I hope there are some convenient built-ins or browser console/repl support.

Visual Studio Code reporting syntax issue with valid regex? [duplicate]

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

What all can you do with match in Javascript? [duplicate]

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

How to convert PHP Regex to jQuery Regex [duplicate]

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

What's the best regex to validate names? [duplicate]

This question already has answers here:
Regular expression for first and last name
(28 answers)
Regex for names
(27 answers)
Closed 8 years ago.
I'm creating a web store and I need to validate inputs with JavaScripts so the user doesn't have to submit a form to be given the PHP errors (although I'm also validating the form with PHP).
What I came up with is the following regex:
/^[a-zA-Z]+$/
But the above regex would only allow alpha characters whereas I also want to allow characters such as ' and - since obviously names may also contain these two characters. My question is, how to make a regex to allow alpha characaters AND the two characters above.
Besides that I also have one more question which just came in my mind, characters such as ă will pass the above validation ?
By adding them to your character group like so
/^[a-zA-Z'-]+$/

Categories

Resources