Expressions Flashcards
1
Q
Regular expressions
A
-Used in programming languages to match parts of strings.
2
Q
Test method
A
-Many ways to test regexes.
Code: -.test() - let myString = "Hello, World!"; let myRegex = /Hello/; let result = myRegex.test(myString); // Change this line
console.log(result);
- Applies to strings placed in the ()
- Returns true or false
3
Q
Match literal strings with different possibilities
A
- Use the alternation or OR operator
- Matches patterns either before or after it
- Can search for more than one pattern (add more OR operators)
Code:
‘|’
myPetRegex = /cat|bird|dog|fish/