{"id":515,"date":"2023-09-16T15:39:10","date_gmt":"2023-09-16T07:39:10","guid":{"rendered":""},"modified":"2023-09-17T00:42:44","modified_gmt":"2023-09-16T16:42:44","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f-%e5%8c%b9%e9%85%8d%e8%a7%84%e5%88%99","status":"publish","type":"post","link":"https:\/\/mushiming.com\/515.html","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f\u2014\u2014\u5339\u914d\u89c4\u5219"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5339\u914d\u89c4\u5219\u662f\u4ece\u5de6\u5230\u53f3\u6309\u89c4\u5219\u5339\u914d\u3002\u6211\u4eec\u9996\u5148\u6765\u770b\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u505a\u7cbe\u786e\u5339\u914d\u3002<\/p>\n

\u5bf9\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0fabc\u6765\u8bf4\uff0c\u5b83\u53ea\u80fd\u7cbe\u786e\u5730\u5339\u914d\u5b57\u7b26\u4e32\"abc\"\uff0c\u4e0d\u80fd\u5339\u914d\"ab\"\uff0c\u201cAbc\u201d\uff0c\"abcd\"\u7b49\u5176\u4ed6\u4efb\u4f55\u5b57\u7b26\u4e32\u3002<\/p>\n

\u5982\u679c\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\u7279\u6b8a\u5b57\u7b26\uff0c\u90a3\u5c31\u9700\u8981\u7528\\\u8f6c\u4e49\u3002\u4f8b\u5982\uff0c\u6b63\u5219\u8868\u8fbe\u5f0fa&c\uff0c\u5176\u4e2d&\u662f\u7528\u6765\u5339\u914d\u7279\u6b8a\u5b57\u7b26&\u7684\uff0c\u5b83\u80fd\u7cbe\u786e\u5339\u914d\u5b57\u7b26\u4e32\"a&c\"\uff0c\u4f46\u4e0d\u80fd\u5339\u914d\"ac\"\u3001\u201ca-c\u201d\u3001\"a&&c\"\u7b49\u3002<\/p>\n

\u8981\u6ce8\u610f\u6b63\u5219\u8868\u8fbe\u5f0f\u5728Java\u4ee3\u7801\u4e2d\u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\uff0c\u5bf9\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0fa&c\u6765\u8bf4\uff0c\u5bf9\u5e94\u7684Java\u5b57\u7b26\u4e32\u662f\"a\\&c\"\uff0c\u56e0\u4e3a\\\u4e5f\u662fJava\u5b57\u7b26\u4e32\u7684\u8f6c\u4e49\u5b57\u7b26\uff0c\u4e24\u4e2a\\\u5b9e\u9645\u4e0a\u8868\u793a\u7684\u662f\u4e00\u4e2a\\\uff1a<\/p>\n

\/\/ regex<\/span>\n\npublic<\/span> class<\/span> Main<\/span> { \n   <\/span>\n    public<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>\n        String re1 =<\/span> \"abc\"<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"abc\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\/\/true<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"Abc\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\/\/false<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"abcd\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\/\/false<\/span>\n\n        String re2 =<\/span> \"a\\\\&c\"<\/span>;<\/span> \/\/ \u5bf9\u5e94\u7684\u6b63\u5219\u662fa\\&c<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"a&c\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\/\/true<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"a-c\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\/\/false<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"a&&c\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\/\/false<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u5982\u679c\u60f3\u5339\u914d\u975eASCII\u5b57\u7b26\uff0c\u4f8b\u5982\u4e2d\u6587\uff0c\u90a3\u5c31\u7528\\u####\u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u4f8b\u5982\uff1aa\\u548cc\u5339\u914d\u5b57\u7b26\u4e32\"a\u548cc\"\uff0c\u4e2d\u6587\u5b57\u7b26\u548c\u7684Unicode\u7f16\u7801\u662f548c\u3002<\/p>\n

\u5339\u914d\u4efb\u610f\u5b57\u7b26<\/h2>\n

\u7cbe\u786e\u5339\u914d\u5b9e\u9645\u4e0a\u7528\u5904\u4e0d\u5927\uff0c\u56e0\u4e3a\u6211\u4eec\u76f4\u63a5\u7528String.equals()\u5c31\u53ef\u4ee5\u505a\u5230\u3002\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u60f3\u8981\u7684\u5339\u914d\u89c4\u5219\u66f4\u591a\u7684\u662f\u6a21\u7cca\u5339\u914d\u3002\u6211\u4eec\u53ef\u4ee5\u7528.\u5339\u914d\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n

\u4f8b\u5982\uff0c\u6b63\u5219\u8868\u8fbe\u5f0fa.c\u4e2d\u95f4\u7684.\u53ef\u4ee5\u5339\u914d\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\uff0c\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u5b57\u7b26\u4e32\u90fd\u53ef\u4ee5\u88ab\u5339\u914d\uff1a<\/p>\n

    \n
  • \u201cabc\u201d\uff0c\u56e0\u4e3a.\u53ef\u4ee5\u5339\u914d\u5b57\u7b26b\uff1b<\/li>\n
  • \u201ca&c\u201d\uff0c\u56e0\u4e3a.\u53ef\u4ee5\u5339\u914d\u5b57\u7b26&\uff1b<\/li>\n
  • \u201cacc\u201d\uff0c\u56e0\u4e3a.\u53ef\u4ee5\u5339\u914d\u5b57\u7b26c\u3002<\/li>\n<\/ul>\n

    \u5339\u914d\u6570\u5b57<\/h2>\n

    \u7528.\u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\uff0c\u8fd9\u4e2a\u53e3\u5b50\u5f00\u5f97\u6709\u70b9\u5927\u3002\u5982\u679c\u6211\u4eec\u53ea\u60f3\u5339\u914d0~9\u8fd9\u6837\u7684\u6570\u5b57\uff0c\u53ef\u4ee5\u7528\\d\u5339\u914d\u3002\u4f8b\u5982\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f00\\d\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

      \n
    • \u201c007\u201d\uff0c\u56e0\u4e3a\\d\u53ef\u4ee5\u5339\u914d\u5b57\u7b267\uff1b<\/li>\n
    • \u201c008\u201d\uff0c\u56e0\u4e3a\\d\u53ef\u4ee5\u5339\u914d\u5b57\u7b268\u3002<\/li>\n<\/ul>\n

      \u5b83\u4e0d\u80fd\u5339\u914d\"00A\"\uff0c\u201c0077\u201d\uff0c\u56e0\u4e3a\\d\u4ec5\u9650\u5355\u4e2a\u6570\u5b57\u5b57\u7b26\u3002<\/p>\n

      \u5339\u914d\u5e38\u7528\u5b57\u7b26<\/h2>\n

      \u7528\\w\u53ef\u4ee5\u5339\u914d\u4e00\u4e2a\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\uff0cw\u7684\u610f\u601d\u662fword\u3002\u4f8b\u5982\uff0cjava\\w\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

        \n
      • \u201cjavac\u201d\uff0c\u56e0\u4e3a\\w\u53ef\u4ee5\u5339\u914d\u82f1\u6587\u5b57\u7b26c\uff1b<\/li>\n
      • \u201cjava9\u201d\uff0c\u56e0\u4e3a\\w\u53ef\u4ee5\u5339\u914d\u6570\u5b57\u5b57\u7b269\uff1b\u3002<\/li>\n
      • \u201cjava_\u201d\uff0c\u56e0\u4e3a\\w\u53ef\u4ee5\u5339\u914d\u4e0b\u5212\u7ebf_\u3002<\/li>\n<\/ul>\n

        \u5b83\u4e0d\u80fd\u5339\u914d\"java#\"\uff0c\"java \"\uff0c\u56e0\u4e3a\\w\u4e0d\u80fd\u5339\u914d#\u3001\u7a7a\u683c\u7b49\u5b57\u7b26\u3002<\/p>\n

        \u5339\u914d\u7a7a\u683c\u5b57\u7b26<\/h2>\n

        \u7528\\s\u53ef\u4ee5\u5339\u914d\u4e00\u4e2a\u7a7a\u683c\u5b57\u7b26\uff0c\u6ce8\u610f\u7a7a\u683c\u5b57\u7b26\u4e0d\u4f46\u5305\u62ec\u7a7a\u683c\uff0c\u8fd8\u5305\u62ectab\u5b57\u7b26\uff08\u5728Java\u4e2d\u7528\\t\u8868\u793a\uff09\u3002\u4f8b\u5982\uff0ca\\sc\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

          \n
        • \u201ca c\u201d\uff0c\u56e0\u4e3a\\s\u53ef\u4ee5\u5339\u914d\u7a7a\u683c\u5b57\u7b26\uff1b<\/li>\n
        • \u201ca c\u201d\uff0c\u56e0\u4e3a\\s\u53ef\u4ee5\u5339\u914dtab\u5b57\u7b26\\t\u3002<\/li>\n<\/ul>\n

          \u5b83\u4e0d\u80fd\u5339\u914d\"ac\"\uff0c\"abc\"\u7b49\u3002<\/p>\n

          \u5339\u914d\u975e\u6570\u5b57<\/h2>\n

          \u7528\\d\u53ef\u4ee5\u5339\u914d\u4e00\u4e2a\u6570\u5b57\uff0c\u800c\\D\u5219\u5339\u914d\u4e00\u4e2a\u975e\u6570\u5b57\u3002\u4f8b\u5982\uff0c00\\D\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

          \u201c00A\u201d\uff0c\u56e0\u4e3a\\D\u53ef\u4ee5\u5339\u914d\u975e\u6570\u5b57\u5b57\u7b26A\uff1b
          \u201c00#\u201d\uff0c\u56e0\u4e3a\\D\u53ef\u4ee5\u5339\u914d\u975e\u6570\u5b57\u5b57\u7b26#\u3002
          00\\d\u53ef\u4ee5\u5339\u914d\u7684\u5b57\u7b26\u4e32\"007\"\uff0c\"008\"\u7b49\uff0c00\\D\u662f\u4e0d\u80fd\u5339\u914d\u7684\u3002<\/p>\n

          \u7c7b\u4f3c\u7684\uff0c\\W\u53ef\u4ee5\u5339\u914d\\w\u4e0d\u80fd\u5339\u914d\u7684\u5b57\u7b26\uff0c\\S\u53ef\u4ee5\u5339\u914d\\s\u4e0d\u80fd\u5339\u914d\u7684\u5b57\u7b26\uff0c\u8fd9\u51e0\u4e2a\u6b63\u597d\u662f\u53cd\u7740\u6765\u7684\u3002<\/p>\n

          public<\/span> class<\/span> Main<\/span> { \n   <\/span>\n    public<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>\n        String re1 =<\/span> \"java\\\\d\"<\/span>;<\/span> \/\/ \u5bf9\u5e94\u7684\u6b63\u5219\u662fjava\\d<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"java9\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"java10\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"javac\"<\/span>.<\/span>matches<\/span>(<\/span>re1)<\/span>)<\/span>;<\/span>\n\n        String re2 =<\/span> \"java\\\\D\"<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"javax\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"java#\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"java5\"<\/span>.<\/span>matches<\/span>(<\/span>re2)<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

          \u91cd\u590d\u5339\u914d
          \u6211\u4eec\u7528\\d\u53ef\u4ee5\u5339\u914d\u4e00\u4e2a\u6570\u5b57\uff0c\u4f8b\u5982\uff0cA\\d\u53ef\u4ee5\u5339\u914d\"A0\"\uff0c\u201cA1\u201d\uff0c\u5982\u679c\u8981\u5339\u914d\u591a\u4e2a\u6570\u5b57\uff0c\u6bd4\u5982\"A380\"\uff0c\u600e\u4e48\u529e\uff1f<\/p>\n

          \u4fee\u9970\u7b26\u53ef\u4ee5\u5339\u914d\u4efb\u610f\u4e2a\u5b57\u7b26\uff0c\u5305\u62ec0\u4e2a\u5b57\u7b26\u3002\u6211\u4eec\u7528A\\d<\/em>\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

            \n
          • A\uff1a\u56e0\u4e3a\\d*\u53ef\u4ee5\u5339\u914d0\u4e2a\u6570\u5b57\uff1b<\/li>\n
          • A0\uff1a\u56e0\u4e3a\\d*\u53ef\u4ee5\u5339\u914d1\u4e2a\u6570\u5b570\uff1b<\/li>\n
          • A380\uff1a\u56e0\u4e3a\\d*\u53ef\u4ee5\u5339\u914d\u591a\u4e2a\u6570\u5b57380\u3002<\/li>\n<\/ul>\n

            \u4fee\u9970\u7b26+\u53ef\u4ee5\u5339\u914d\u81f3\u5c11\u4e00\u4e2a\u5b57\u7b26\u3002\u6211\u4eec\u7528A\\d+\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

              \n
            • A0\uff1a\u56e0\u4e3a\\d+\u53ef\u4ee5\u5339\u914d1\u4e2a\u6570\u5b570\uff1b<\/li>\n
            • A380\uff1a\u56e0\u4e3a\\d+\u53ef\u4ee5\u5339\u914d\u591a\u4e2a\u6570\u5b57380\u3002<\/li>\n<\/ul>\n

              \u4f46\u5b83\u65e0\u6cd5\u5339\u914d\"A\"\uff0c\u56e0\u4e3a\u4fee\u9970\u7b26+\u8981\u6c42\u81f3\u5c11\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n

              \u4fee\u9970\u7b26?\u53ef\u4ee5\u5339\u914d0\u4e2a\u6216\u4e00\u4e2a\u5b57\u7b26\u3002\u6211\u4eec\u7528A\\d?\u53ef\u4ee5\u5339\u914d\uff1a<\/p>\n

                \n
              • A\uff1a\u56e0\u4e3a\\d?\u53ef\u4ee5\u5339\u914d0\u4e2a\u6570\u5b57\uff1b<\/li>\n
              • A0\uff1a\u56e0\u4e3a\\d?\u53ef\u4ee5\u5339\u914d1\u4e2a\u6570\u5b570\u3002<\/li>\n<\/ul>\n

                \u4f46\u5b83\u65e0\u6cd5\u5339\u914d\"A33\"\uff0c\u56e0\u4e3a\u4fee\u9970\u7b26?\u8d85\u8fc71\u4e2a\u5b57\u7b26\u5c31\u4e0d\u80fd\u5339\u914d\u4e86\u3002<\/p>\n

                \u5982\u679c\u6211\u4eec\u60f3\u7cbe\u786e\u6307\u5b9an\u4e2a\u5b57\u7b26\u600e\u4e48\u529e\uff1f\u7528\u4fee\u9970\u7b26{n}\u5c31\u53ef\u4ee5\u3002A\\d{3}\u53ef\u4ee5\u7cbe\u786e\u5339\u914d\uff1a<\/p>\n

                  \n
                • A380\uff1a\u56e0\u4e3a\\d{3}\u53ef\u4ee5\u5339\u914d3\u4e2a\u6570\u5b57380\u3002<\/li>\n<\/ul>\n

                  \u5982\u679c\u6211\u4eec\u60f3\u6307\u5b9a\u5339\u914dn~m\u4e2a\u5b57\u7b26\u600e\u4e48\u529e\uff1f\u7528\u4fee\u9970\u7b26{n,m}\u5c31\u53ef\u4ee5\u3002A\\d{3,5}\u53ef\u4ee5\u7cbe\u786e\u5339\u914d\uff1a<\/p>\n

                    \n
                  • A380\uff1a\u56e0\u4e3a\\d{3,5}\u53ef\u4ee5\u5339\u914d3\u4e2a\u6570\u5b57380\uff1b<\/li>\n
                  • A3800\uff1a\u56e0\u4e3a\\d{3,5}\u53ef\u4ee5\u5339\u914d4\u4e2a\u6570\u5b573800\uff1b<\/li>\n
                  • A38000\uff1a\u56e0\u4e3a\\d{3,5}\u53ef\u4ee5\u5339\u914d5\u4e2a\u6570\u5b5738000\u3002<\/li>\n<\/ul>\n

                    \u5982\u679c\u6ca1\u6709\u4e0a\u9650\uff0c\u90a3\u4e48\u4fee\u9970\u7b26{n,}\u5c31\u53ef\u4ee5\u5339\u914d\u81f3\u5c11n\u4e2a\u5b57\u7b26\u3002<\/p>\n

                    \u5c0f\u7ed3<\/h2>\n

                    \u5355\u4e2a\u5b57\u7b26\u7684\u5339\u914d\u89c4\u5219\u5982\u4e0b\uff1a
                    \"\u6b63\u5219\u8868\u8fbe\u5f0f\u2014\u2014\u5339\u914d\u89c4\u5219
                    \u591a\u4e2a\u5b57\u7b26\u7684\u5339\u914d\u89c4\u5219\u5982\u4e0b\uff1a
                    \"\u6b63\u5219\u8868\u8fbe\u5f0f\u2014\u2014\u5339\u914d\u89c4\u5219<\/p>\n","protected":false},"excerpt":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f\u2014\u2014\u5339\u914d\u89c4\u5219\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5339\u914d\u89c4\u5219\u662f\u4ece\u5de6\u5230\u53f3\u6309\u89c4\u5219\u5339\u914d\u3002\u6211\u4eec\u9996\u5148\u6765\u770b\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u505a\u7cbe\u786e\u5339\u914d\u3002\u5bf9\u4e8e\u6b63\u5219\u8868...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/515"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=515"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/515\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}