Home > Java > javaTutorial > How to write regular expression in java

How to write regular expression in java

小老鼠
Release: 2024-01-05 15:28:47
Original
822 people have browsed it

Commonly used regular expressions: 1. Match any character: .; 2. Match numbers: \d; 3. Match letters: \w; 4. Match white space characters: \s; 5. Match newlines character: \n; 6. Match newline character: \r; 7. Match specific character set: []; 8. Match non-specific character set: [^]; 9. Match the beginning: ^; 10. Match the end: $; 11. Match word boundary: \b; 12. Match zero or more times: *; 13. Match one or more times: ; 14. Match zero or one time: ? and so on.

How to write regular expression in java

Operating system for this tutorial: Windows 10 system, Dell G3 computer.

Regular expressions in Java can be processed through Java's regular expression library. The following are some commonly used regular expressions:

  1. Matches any character: .
  2. Matches numbers: \d
  3. Matches letters: \w
  4. Match whitespace characters: \s
  5. Match newlines: \n
  6. Match newlines: \r
  7. Match specific character sets: []
  8. Matches a non-specific character set: [^]
  9. Matches the beginning: ^
  10. Matches the end: $
  11. Matches a word boundary: \b
  12. Matches zero or Multiple times: *
  13. Matches one or more times:
  14. Matches zero or one time: ?
  15. Matches the previous subexpression one or more times: {n,}
  16. Matches the preceding subexpression zero or one time: {n,?}
  17. Matches the preceding subexpression exactly n times: {n}
  18. Match pattern occurs Any number of times (including zero): *?
  19. Matches the pattern exactly n times: {n}?
  20. Matches any character except newlines: [\S\s]
  21. Matches any character that is not a newline: [^\n]
  22. Matches any character except the specified character set: [^...]
  23. Matches the beginning of the string :\A
  24. End of matching string:\z
  25. Start position of matching word:\y
  26. End position of matching word:\Y
  27. Not Greedy mode: *? ? ?? {n,}? {n,}?? \A\z\y\Y
  28. Non-capturing group: (?:...)
  29. Capturing group: (...)?
  30. Backreference: (...)\k<...>
  31. Non-capturing group and backreference combined: (?: ...)\k<...>
  32. Ignore case pattern: (?i)

The above is the detailed content of How to write regular expression in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template