Regex describing a regex 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 6 years ago.
Improve this question
I am surprised that an answer to this is not easily found.
I am in the process of making a JSON schema. I have an object and one of it's properties is a string containing a regex pattern. This property must contain only regex.
So, this question is realistically two questions in one:
What is the regex pattern that describes regex patterns (javascript-compatible please)?
Secondly, how do I apply this to JSON schema (in the "pattern" property or even in the "patternProperty"1 property)?
1: I have no idea what purpose would require you to apply this in "patternProperty", but someone out there could find it useful
NOTE: Since, JSONschema is JSON and JSON is JavaScript-based, JavaScript scripters may find the solution (to the JSONschema-side of the question), as well as the problem, useful in their scripts.

Regexes can have nested parentheses.
Therefore, they are not describable by a regular expression.
Sorry.

Related

What is a List ? [JavaScript interview question] [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
What exactly is a "List" in JavaScript?
I got asked this question and I'm a professional of five years but this made me fumble.
I understand Arrays, Stacks, Queues, even Linked Lists.
But isn't a List just an Array in JavaScript? Because then I got asked what the difference between a List and an Array was, and I said no difference - and never got to know if that was right.
I understand the differences between the data structures List and Array in C# and Python but I don't get this one for JavaScript.
I understand the downvotes ... it was indeed a dumb question, I think I should have known that Lists weren't a type in JavaScript and tackle the dumb question that way.
For anyone this may prove useful: For front-end engineer interviews, make sure you know that JavaScript is a dynamic language, meaning the data structures are very different from static typed languages like C and Java, and even have different meanings in Python even though Python is a dynamically typed language similar to JavaScript.

Regex time validation [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
So i want to make a regular expression to validate times between 12:00 and 22:00 but i cant get my head around making expressions and cant find any examples online that i can just swap out examples of. Can anybody help me?
You can use the following regular expression:
^((1[2-9]|2[0-1]):[0-5][0-9]|22:00)$
This is how it works:
^ and $ match start and end of string, and they are there to prevent matching also 112:009 for example (which contains 12:00).
[2-9] matches numbers between 2 and 9, and (a|b) would match either a or b.
Debuggex Demo

Regex pattern with special characters, digits and letters all combined [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
Say I have a regex pattern like this:
/^\*HELLO\*/
Just looking for the string "*HELLO*". But then I completely want to change it up so I do this:
/^\*&$&^*2#H\*/
Now I'm looking for the string "*&$&^*2#H*".
How should I change my regex pattern to check for such a complex string with all those different characters?
You should escape the special characters in your pattern, wich are used as tokens by Regex, such as *,^ and $. Or you will end up with an error claiming about a wrong pattern in your regex.
This is how should be your regex: /\*&\$&\^\*2#H\*/.
Furthermore if you are searching for the string with .indexOf() or .includes() methods, you can just pass the string as it is.
str.indexOf("^\*&$&^*2#H\*");

Why javascript function name custom is a lower case word followed by a capitalized word, just like `orangeCost`? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I was learning javascript from codecademy today.
There is one thing that confuse me a lot, in its tutorial, it use function names like orangeCost. like in this link:
http://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661
In my behaviour, I feel both orange_cost and OrangeCost just fine.
Why in this broadly read tutorial, they use such variable name(orangeCost)?
Is there some history in it, or it can prevent some kind of catastrophe?
It's just a human convention.
In other environments, instead of using camel-casing, they use pascal-casing (orangeJuice would be camel-casing while OrangeJuice pascal-casing).
Conventions are powerful to let others understand our code as it's written in a standarized way.
It could happen that some convention would be ugly, but it's better to follow a convention than going alone the way.
Anyway, either camel or pascal casing aren't ugly per se. It's just our taste what turns something into ugly or beautiful.
An exception to the rule
Brainfuck code is ugly. I believe that there's a human convention about this ;)

Regex Clarification [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
I am relatively new to regex. I found this regex being used and was not able to understand how exactly it is working.
([\(]*([\w][\/]?[\w]?(%)?(,)?)*|[\/.]|[\w]([\-\*|\+|\\|\<\>|\=]([\(]*[\w][\/]?(%)?[\)]?[\)]?(,)?)+)*[\)]?)*$/
I understand most of the basic syntax but not able to understand what this means.
Any clarity on this will be appreciated! This is used in javascript so the tag.
Thanks!
The same without uneeded characters:
/(\(*(\w\/?\w?(%)?(,)?)*|[\/.]|\w([-*+\\<>=](\(*\w\/?(%)?\)?\)?(,)?)+)*\)?)*$/
This pattern can match this kind of string (or nothing):
(((a/b%,(((a/b%,///./././(((a/b%,k*((((((((P/%)),)
your regex:
([\(]*([\w][\/]?[\w]?(%)?(,)?)*|[\/.]|[\w]([\-\*|\+|\\|\<\>|\=]([\(]*[\w][\/]?(%)?[\)]?[\)]?(,)?)+)*[\)]?)*$/
can be visualized as:
Debuggex Demo
unless there is a typo in your regex, it will never match anything; the regex ends with $/ which means end of the string followed by /, unless you are matching over multiple lines. If this was homework, I would say the teacher is making a bad joke because of the $/ that doesn't usually match anything.
After some simplification you get:
(\(*(\w\/?\w?(%)?(,)?)*|[\/.]|\w([-*|+\\<>=](\(*\w\/?(%)?\)?\)?(,)?)+)*\)?)*$/
If you don't care about grouping, then this is similar:
(\(|[\/.]|(\w\/?\w?%?,?)|\w([-*|+\\<>=](\(*\w\/?%?\)?\)?,?)+)*\)?)*$/
Debuggex Demo
this takes advantage that (a*|b*)* can be simplified into (a|b)*
To learn more about regex REFER : regex101 give your code there and read explanation .
Your regex: ([\(]*([\w][\/]?[\w]?(%)?(,)?)*|[\/.]|[\w]([\-\*|\+|\\|\<\>|\=]([\(]*[\w][\/]?(%)?[\)]?[\)]?(,)?)+)*[\)]?)*$
Will match anything like
(d/f%,
something
122
But will fail to match something like
--{}
Explanation :

Categories