SoFunction
Updated on 2025-03-08

Example analysis of Java regular matching Chinese method

This article describes the method of Java regular matching Chinese. Share it for your reference, as follows:

1. Match the content between double quotes:

public void test1() {
  // Match content between double quotes  String pstr = "\"([^\"]+)\"";
  Pattern p = (pstr);
  Matcher m = ("\"goodjob\"");
  (() ? (1) : "nothing");
  // Test Chinese  m = ("\"goodjobThere is Chinese in it\"");
  (() ? (1) : "nothing");
}

2. Chinese content also matches:

public void test2() {
  // Chinese content also matches  String pstr = "\"([^\"|[\u4e00-\u9fa5]]+)\"";
  Pattern p = (pstr);
  Matcher m = ("\"goodjobThere is Chinese in it\"");
  (() ? (1) : "nothing");
  // Test punctuation  m = ("\"goodjobThere are also punctuation points!\"");
  (() ? (1) : "nothing");
}

3. Punctuation matches:

public void test3() {
  // Punctuation matches  Pattern p = ("\"([^\"|[\u4e00-\u9fa5\ufe30-\uffa0]]+)\"");
  Matcher m = ("\"goodjobThere are also punctuation points!\"");
  (() ? (1) : "nothing");
}

The output of the above three programs is as follows:

goodjob
nothing
goodjobThere is Chinese in it
nothing
goodjobThere are also punctuation points!

PS: Here are two very convenient regular expression tools for your reference:

JavaScript regular expression online testing tool:
http://tools./regex/javascript

Regular expression online generation tool:
http://tools./regex/create_reg

I hope this article will be helpful to everyone's Java programming.