Guest User

6.Текстообработка и регулярни изрази

a guest
Apr 14th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. Текстообработка и регулярни изрази
  2. Типът String е immutable type, т.е. ако променим дадена променлива от тип String, то се създава нова променлива, а не се променя старата
  3.  
  4. В Java, стринговете се сравняват чрез метода .equals()
  5.  
  6. Регулярен израз – последователност от символи, които формират някаква шаблон, по който се търси
  7.  
  8. [character_group] – matches any single character in character_group
  9. [^] - negation
  10. [first-last] – character range: matches any single character in the range from first to last (according to the ASCII table)
  11. \w – matches any word character (a-z, A-Z, 0-9, _)
  12. \W - matches any non-word character – the opposite to \w
  13. \s – matches any whitespace character (\r\n, \t, ‘ ‘)
  14. \S – matches any non-whitespace character
  15. \d – matches any digit character
  16. \D – matches any non-digit character
  17.  
  18. * - matches the previous element zero or more times (as many times as possible)
  19. + - matches the previous element one or more times (as many times as possible)
  20. ? - matches the previous element zero or one time
  21. +? – matches between one and unlimited times (as few times as possible) – lazy
  22. *? – matches between zero and unlimited times (as few times as possible) – lazy
  23.  
  24. {n} - matches the previous element exactly n times
  25. {n,} - matches the previous element at least n times
  26. {n,m}- matches the previous element at least n times, but no more than m times
  27.  
  28. ^ - the match must start at the beginning of the string or line
  29. $ - the match must occur at the end of the string or before \n
  30.  
  31. \b – the match must occur on a boundary between a \w(alphanumeric) and a \W(non-alphanumeric) character
  32. \B – the match must not occur on a boundary between a \w(alphanumeric) and a \W(non-alphanumeric) character
  33.  
  34.  
  35. (subexpression) – captures the matched subexpression and assigns it a number
  36. (?<name>subexpression) – captures the matched subexpression into a named group
  37. (?:subexpression) – defines a non-capturing group
  38. . – matches any character except new line
  39.  
  40. !! look-behinds are more limited than look-aheads, because they do not support quantifiers of varying size such as “*”, “?”, “+”
  41.  
  42. (не работи в C#) The escape sequence \K is similar to a look-behind assertion because it causes any previously-matched characters to be omitted from the final matched string. For example, foo\Kbar matches "foobar" but reports that it has matched "bar".
Add Comment
Please, Sign In to add comment