How does toLowerCase() work in Javascript? [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 7 years ago.
Improve this question
I understand that using that function will make an entire string all lowercase. However, I'm curious in the behind the scenes work. I can't find an explanation anywhere on how it works. Does it basically loop through every index in the string and check to see what the character is and if there is a lower case character available?

In general the best place to look for such information is the ECMAScript specification:
The following steps are taken:
Call CheckObjectCoercible passing the this value as its argument.
Let S be the result of calling ToString, giving it the this value as its argument.
Let L be a String where each character of L is either the Unicode lowercase equivalent of the corresponding character of S or the actual corresponding character of S if no Unicode lowercase equivalent exists.
Return L.
For the purposes of this operation, the 16-bit code units of the Strings are treated as code points in the Unicode Basic Multilingual Plane. Surrogate code points are directly transferred from S to L without any mapping.
The result must be derived according to the case mappings in the Unicode character database (this explicitly includes not only the UnicodeData.txt file, but also the SpecialCasings.txt file that accompanies it in Unicode 2.1.8 and later).
Step 3 is the part you're really interested in. As you can see, the details of how "L" is produced are up to the implementation. If you're interested in going deeper the next place to look would be e.g. the V8 engine itself.

Related

how to extract an id from a javascript in jmeter? [closed]

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 1 year ago.
Improve this question
i have a problem with extracting an id from a request in javascript. Let me explain, although I have inserted as a post processor a regular expression extractor with the following regular expression: (? <= Store_id :) \ d, the extraction of the value does not happen. Strangely, however, when I use this expression in the view result tree search this seems to work, the search finds me exactly the value I need, could you tell me where am I wrong?
You need to wrap the value you want as a group with parenthesis:
store_id:(\d+)
Regular expressions are case-sensitive by default in JS. Try this:
(?<=store_id:)\d+
I replaced \d with \d+ because probably the ID may have more than one digit. If that's not the case, you can use \d.
Try something like:
{store_id\s*:\s*(\d+)
where:
\s* - optional number of whitespaces
\d+ - any number of digits
() - grouping
See Regular Expressions user manual chapter for more details
If you have problems when it comes to coming up with a proper regular expression alternatively you can go for the Boundary Extractor which basically extracts everything between left and right boundaries, it consumes less resources and works faster. More information: The Boundary Extractor vs. the Regular Expression Extractor in JMeter

Is it possible to make a regex that accepts ANY substring [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
I'm somewhat new to regex. I understand most of the basics but what I'm trying to do is beyond my knowledge, and may not even be possible.
I'm trying to make a regex in JavaScript that can match a series of function calls in the following pattern.
Name.Name(Params).Name(Params)
The names could be any standard java function name. I understand how do to this part. The params though can be different number of parameters (Currently only 0-2)
My biggest issue however is that params could potentially take ANY string with either a single or double quotation mark, or variable names. I have added some examples below as I need all of these to work with my regular expression (if Possible).
Examples:
Func.Foo().Bar()
Foo.Bar('foo', bar).Foobar()
Foo.Bar("foo", "bar").bar(')')
Foo.Bar('/"foo/"').bar("foo(bar/")")
My main concern here is I cant just look for a opening and parentheses or even 2 quotation marks.
Is it possible to use a regex so that I can parse the function call and parameters out?
The short answer to the Question in the title is yes, you can build a regex that matches any substring. But unfortunately that is not what you want. If you allow arbitrary substrings your regex will either match many cases you dont want to match or it will become extremely complex (see the email regex for an example).
What you want is a tokenizer!(https://medium.freecodecamp.org/how-to-build-a-math-expression-tokenizer-using-javascript-3638d4e5fbe9)
Edit: for the solutions in the comments: the ast parser is for java, the author wants to use javascript.

faster way for search between boolean comparision vs exact match search in javascript [closed]

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 6 years ago.
Improve this question
I have six different values {string1, string2, .., string6}.
I have to fetch all these values from MongoDB where I compare different conditions. On the basis of these six values I applied my logic.
I need to write an efficient and fast way to compare.
Should I go for regex based search or should I compare six separate Boolean conditions
Which method is best and why?
Note: I must compare these six values with my data.
I wouldn't advise using Regex for this, but in any case you won't see any performance hit unless your querying a heck of allot more items. For simplicity and readability I'd recommend using the switch() statement.
Well, if you want to check equality of a variable between six different string values, it is advisable to use switch over if-else.
Please go through the following links:
When to use if-else and switch
How switch statements are faster than if-else

sanitize upper vs lower case [closed]

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 7 years ago.
Improve this question
Is there a reason that when sanitizing a string, the characters are converted to lowercase as opposed to uppercase?
I've see this convention in many languages, but in terms of my current environment, we'll say Rails and/or Javascript
No specific reason to my knowledge, but neither uppercasing nor lowercasing is the whole story in the Unicode world.
For example, the German letter ß is exactly equivalent to ss; they're both lowercase, and a word spelled with ß can also be spelled with ss.
Conversely, in Turkish, ı (dotless i) is distinct from i (dotted i), but unless your locale is Turkish, uppercasing either one produces I (dotless ASCII I). This changes meaning too. You don't want to use the wrong one; they aren't equivalent.
Because of this, some programming languages offer more specific "case normalizing" conversions per the case folding rules in section 3.13 of the Unicode standard; Python 3.3 introduced str.casefold for that reason. It's much like .lower(), but will also normalize stuff like ß to ss because they're logically equivalent (if you're uniquifying, you wouldn't want to treat two strings that differ only in ß vs. ss to be treated as different).
If you don't have case folding available in your language, then the distinction between normalizing as upper vs. lower case is mostly by convention.
Javascript has toLowerCase() as well as toUpperCase(). You can use either!
I think the answer to your question though really stems from unix systems deciding many decades ago to use case sensitivity and having all lower case commands. This translated to case sensitive urls in Apache, and to be cross O/S compatible, we just made sure everything was always lowercase.
I guess all upper case could be and is used at times, but it's also obnoxious :)

filter invalid mobile numbers with Javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to write in java script to exclude invalid mobile numbers that are entered into the SQL database. i currently have the regex function within my script however it cant pick up brackets(), resulting in numbers such as (123) 456789 not being included.
Is there any extension to the regex i could use to include brackets?
There is a free google API that can validate numbers for you, even tell you the country code etc.
https://code.google.com/p/libphonenumber/
Never tried it, but I evaluated it once for another project I worked on.
This is Java, not JS, but still you may consider moving your validation logic to a Java servlet and invoke using an AJAX call.
1) This would expect atleast one white space character after parenthesis
/\(\d{3}\)\s+\d{6}/
Or
/\(\d+\)\s+\d+/ //in case of digit not specified.
2) This would match with or without space
/\(\d{3}\)\s*\d{6}/
//eg:-
// (123)456789
// (123) 456789

Categories

Resources