第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將文本匹配到多個(gè)組的正則表達(dá)式

將文本匹配到多個(gè)組的正則表達(dá)式

素胚勾勒不出你 2021-09-14 21:12:30
我正在嘗試設(shè)置一個(gè)正則表達(dá)式來(lái)匹配文本,并且我希望一個(gè)特定的字符串與文本其余部分的單獨(dú)組匹配(如果存在)。例如,如果我的字符串是this is a test,我想this is a匹配第一組并test匹配第二組。我正在使用 python 正則表達(dá)式庫(kù)。以下是我想要的結(jié)果的更多示例this is a test- 第 1 組:this is a,第 2 組:testone day at a time- 第 1 組:one day at a time,第 2 組:one day test is- 第 1 組:one day,第 2 組:testtesting, 1,2,3 - 不匹配this is not a drill- 第 1 組:this is not a drill,第 2 組:在這些情況下,我在第二組中匹配的特定字符串是 test。我不確定如何設(shè)置正則表達(dá)式以正確匹配這些特定情況。
查看完整描述

2 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以嘗試以下正則表達(dá)式:


^(this.*?)(test)?$

正則表達(dá)式的解釋?zhuān)?/p>


NODE                     EXPLANATION

--------------------------------------------------------------------------------

  ^                        the beginning of the string

--------------------------------------------------------------------------------

  (                        group and capture to \1:

--------------------------------------------------------------------------------

    this                     'this'

--------------------------------------------------------------------------------

    .*?                      any character except \n (0 or more times

                             (matching the least amount possible))

--------------------------------------------------------------------------------

  )                        end of \1

--------------------------------------------------------------------------------

  (                        group and capture to \2 (optional

                           (matching the most amount possible)):

--------------------------------------------------------------------------------

    test                     'test'

--------------------------------------------------------------------------------

  )?                       end of \2 (NOTE: because you are using a

                           quantifier on this capture, only the LAST

                           repetition of the captured pattern will be

                           stored in \2)

--------------------------------------------------------------------------------

  $                        before an optional \n, and the end of the

                           string


查看完整回答
反對(duì) 回復(fù) 2021-09-14
?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

你可以試試這位朋友

^(?:(?!test))(?:(.*)(?=\btest\b)(\btest\b)|(.*))

解釋

  • ^(?:(?!test)) - 負(fù)面展望。不要匹配任何以測(cè)試開(kāi)頭的內(nèi)容。

  • (.*) - 匹配除換行符以外的任何內(nèi)容。

  • (?=\btest\b)- 積極的前瞻。test單詞邊界之間的匹配。

  • (\btest\b)- 捕獲組比賽test。

  • | - 交替與邏輯 OR 相同。

  • (.*) - 匹配除換行符以外的任何內(nèi)容。


查看完整回答
反對(duì) 回復(fù) 2021-09-14
  • 2 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)