gpt4 book ai didi

java - 如何在字符串中使用正则表达式转义 '\'?

转载 作者:行者123 更新时间:2023-12-01 14:20:07 30 4
gpt4 key购买 nike

我的字符串是:

1BFM\",\"1BFR\",\"1BFZ\",\"1BKFH\",\"2BFE1\",\"2BFE2\",\"2BFH1A\",\"2BFH1B\",\"2BFH2A\",\"2BFH2B\",\"2BFM1\",\"2BFM2\",\"2BFP1\",\"2BFP2\",\"2BKIK1\",\"2BKIK2\",\"3BFA1\",\"3BFA2\",\"3BFA3\",\"B1SK\",\"B1MA\",\"BEJ1\",\"BEJ2\",\"BVE\",\"BVJK1\",\"BVJK2\",\"E1EI\",\"E1ME1\",\"E1ME2\",\"E1ME3\",\"E2EI\",\"E2ME1\",\"E2ME2\",\"E3EI\",\"E3ME1\",\"E3ME2\",\"E4EI\",\"E4ME1\",\"E4ME2\",\"FBF\",\"FBFK1A\",\"FBFK1B\",\"FBFK1C\",\"FBFK2A\",\"FBFK2B\",\"K2FR\",\"K3FR\",\"M1MV1\",\"M1MV2\",\"M1MV3\",\"M1SV\",\"M1VK1\",\"M1VK2\",\"M2MV1\",\"M2MV2\",\"M2MV3\",\"M2MV4A\",\"M2MV4B\",\"M2SV\",\"M2VK1\",\"M2VK2\",\"M3MV1\",\"M3MV2\",\"M3MV3\",\"M3SV\",\"M3VK1\",\"M3VK2\",\"M4MV1\",\"M4MV2\",\"M4MV3\",\"M4MV4\",\"M4SV\",\"R2PW\",\"R3PW\",\"R4PW\",\"SG8\",\"SG11A\",\"SG11B\",\"SG12A\",\"SG12B\",\"SG13\",\"TGI11\",\"TGI12\",\"TGI13\",\"TGME11\",\"TGT12\",\"TGT13\",\"TGTM11\",\"TGTM12\",\"TGTM13\",\"VAB\",\"Z2TI\",\"Z3TI\",\"Ab-FWG\",\"FA-CHSE\",\"Fo-CHSE\",\"HM-CHSE\",\"Rd-BSZ\",\"SCHB-FWG\",\"Sl-CHSE\",\"Zp-CHSE\",\"SET\",\"SLT\",\"Fußball-AG\",\"PD\

到目前为止,我的正则表达式如下所示:

(\".*?\")

我现在得到的是这样的:

1BFM\
1BFM\
1BFR\
1BFZ\
1BKFH\
2BFE1\
2BFE2\
2BFH1A\
2BFH1B\
2BFH2A\
2BFH2B\

那么我该怎么做才能使最后一个\也被转义?

最佳答案

您首先需要转义反斜杠。然后,对于 Java,您需要转义两个反斜杠。我认为这应该有效:

(\\\\\".*?\\\\\")

关于java - 如何在字符串中使用正则表达式转义 '\'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17684299/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com