1. Using the new RegExp() constructor // constructor var re = new RegExp("\\\\", "gm"); 2. Using the regular expression literal // regular expression literal var re = /\\/gm; when using the RegExp()constructor, you also need to escape…
Regular Expression Patterns Following lists the regular expression syntax that is available in Python. Pattern Description ^ match beginning of the line. $ match end of line. . match any single character except '\n'. [...] match any single character…
JSON: JavaScript Object Notation {"name": "value", "some": [1, 2, 3]} The only syntax difference between JSON and the object literal is that property names need to be wrapped in quotes to be valid JSON. In object literals th…
1 match = re.search(pat,str) If the search is successful, search() returns a match object or None otherwise. The code match = re.search(pat, str) stores the search result in a variable named "match". Then the if-statement tests the match -- if…
7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. This means that the second time you use the same class to create a new object, you should get the same object that was created the first time. var obj =…
Scenario You want to use just the methods you like, without inheriting all the other methods that you’ll never need. This is possible with the borrowing methods pattern, which benefits from the function methods call() and apply(). // call() example…
Commonalities • There’s a convention on how to name a method, which is to be considered the constructor of the class. • Classes inherit from other classes. • There’s access to the parent class (superclass) from within the child class. The function ta…