Difference between toLocaleLowerCase() and toLowerCase()? [duplicate] - javascript

This question already has answers here:
In what JS engines, specifically, are toLowerCase & toUpperCase locale-sensitive?
(2 answers)
Closed 7 years ago.
What is the difference between these two ?
The description for the toLocaleLowerCase() mentions Converts a string to lowercase letters, according to the host's locale.
What is the host's locale ?

Definition and Usage as per w3schools
The toLocaleLowerCase() method converts a string to lowercase letters, according to the host's current locale.
The locale is based on the language settings of the browser.
Generally, this method returns the same result as the toLowerCase() method. However, for some locales, where language conflict with the regular Unicode case mappings occurs (such as Turkish), the results may vary.

Related

Javascript regex to match equal number of consecutive 1 and 0 [duplicate]

This question already has answers here:
Recursive matching with regular expressions in Javascript
(6 answers)
Closed 4 years ago.
I want to write a regex which matches following scenarios,
10
1100
111000
11110000
// etc. consecutive 1 count should equal consecutive 0 count.
Is it possible to write a regex for this?
I suppose I could write, 1{n}0{n}, but it didn't work here: https://regex101.com/
May be this is not doable with regex?
I can of course do this with a loop. But I want to know if this is possible using regex.
Thank you!!!!
Theoretically the answer is no.
We can write regular expressions for strings that belong to regular languages.
Your case belong to a context free language.

What is the meaning of double at sign (##) before a symbol name [duplicate]

This question already has an answer here:
What does ## ("at at") mean in ES6 JavaScript?
(1 answer)
Closed 5 years ago.
In the context of ES6 symbols, it's often seen that double at sign (##) is placed before a symbol name. Is it just another way to reference a built-in symbol? However, using it in code causes
SyntaxError: Invalid or unexpected token
This has been answered before: What does ## ("at at") mean in ES6 JavaScript?
I am gonna leave this article here too: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols
A summary quote from the spec:
Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless otherwise specified, well-known symbols values are shared by all Code Realms (8.2).
I hope this answers your question :)

encrypting / shortening a long string in JS [duplicate]

This question already has answers here:
String compression in JavaScript
(8 answers)
Closed 6 years ago.
I need to shorten a long string with a variable length and "decode" it back later on.
The string will be built up like this 0011010011 ........ etc.
My problem right now is that the string will be over a thousand characters long which is far far too long to easily copy and paste around.
Any ideas on how to do this?
read more
Javascript doesn't support binary data by default. I would either use an exisiting package such as binstring or write your own encoding function

What ASCII characters are valid for Javascript variable names? [duplicate]

This question already has answers here:
What characters are valid for JavaScript variable names?
(12 answers)
Closed 7 years ago.
I've seen this other question, unfortunately the answers spend too much attention on Unicode and say nothing about normal ASCII characters.
I need to know which 7-bit ASCII characters (0..127) are valid in a Javascript identifier name.
According to this article, this is all about javascript variables :
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
You can use all ASCII codes. but you have to comply with above rules.

javascript method to check a valid URL [duplicate]

This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 9 years ago.
I there any JavaScript way (regex) or module to check if a string is a URL which the follows following schema http://en.wikipedia.org/wiki/URI_scheme.
NOTE -
I have seen other questions related to this in stackoverflow and none of them are satisfactory.
Most of them are the regex which matches the http/https/ftp URL but what about feed or mailto URL or URL with any other schema as specified in http://en.wikipedia.org/wiki/URI_scheme
The following regex does what you are requesting.
It validates a string if it holds a URL as specified in RFC 3986.
Both absolute and relative URLs are supported.
^([a-z][a-z0-9+\-.]*:(//([a-z0-9\-._~%!$&'()*+,;=]+#)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/?[a-z0-9\-._~%!$&'()*+,;=:#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?)?)| ([a-z0-9\-._~%!$&'()*+,;=#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/[a-z0-9\-._~%!$&'()*+,;=:#]+)+/?))(\?[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?(\#[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?$
I did not come up with this regex, it is created by JGSoft

Categories

Resources