Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. # Javascript Regular Expressions
  2.  
  3. A regular expression or regex describes a pattern of characters. It can be used to perform powerful pattern-matching and search-and-replace functions on text.
  4.  
  5. ## Defining Regular Expressions
  6.  
  7. Regular expression literals
  8. let pattern = /s$/;
  9.  
  10. Regular Expression Object
  11. let pattern = new RegExp('s$');
  12.  
  13. Most characters (alphanumeric) describes characters to be matched literally. There are however metacharacters that have special significant meanings.
  14.  
  15. For example in the above case, the first 's' matches itself literally and the '$' is a special character that matches the end of the string. Hence the regular expression matches any string which contains 's' as its last character.
  16.  
  17. ## Literal Characters
  18.  
  19. JavaScript supports certain nonalphabetic characters through escape sequences that begin with backslash (\).
  20.  
  21. Character|Matches
  22. ---------|--------
  23. Alphanumeric Character|itself
  24. \0|The NUL character
  25. \t|Tab
  26. \n|Newline
  27. \v|Vertical Tab
  28. \f|Form feed
  29. \r|Carriage return
  30. \x *nn*|The Latin Character specified by the hexadecimal number **nn**;eg \x0A === \n
  31. \u *xxxx*|The Unicode character specified by the hexadecimal number **xxxx**;eg \u0009 === \t
  32. \c *x*|The control character ^ ** x**;eg \cJ === \n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement