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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用于查找格式錯誤的引用字符串的正則表達式

用于查找格式錯誤的引用字符串的正則表達式

Go
BIG陽 2023-06-19 14:04:24
我正在嘗試為具有起始引號但沒有結(jié)束引號的子字符串構(gòu)建正則表達式。下面是一個示例字符串"The fish was 2 long. I said: Give me that fish!.The fish was 2" long. I said: Give me that fish!."The fish was 2 long. I said: Give me that fish!."The fish "was 2 long". I said: "Give me that fish!.所以表達式的有效輸出是String 1 - The fish was 2 long. I said: Give me that fish!String 2 -  long. I said: Give me that fish!.String 3 - No outputString 4 - Give me that fish!.任何想法如何構(gòu)建正則表達式。
查看完整描述

1 回答

?
喵喵時光機

TA貢獻1846條經(jīng)驗 獲得超7個贊

可以用正則表達式做所有事情.. 需要更多時間來完善解決方案。但是使用一些字符串函數(shù)會讓你輕松一些。


希望這可以幫助??!


package main


import (

"fmt"

"regexp"

"strings"

)


func main() {

str := `

    "The fish was 2 long. I said: Give me that fish!.

The fish was 2" long. I said: Give me that fish!.

"The fish was 2 long. I said: Give me that fish!."

""sdfsdf

`

splitStr := strings.Split(str, "\n")

re := regexp.MustCompile(`"{1}[A-Za-z0-9 .:!]+"{0}[A-Za-z0-9 .:!]+$`)

for _,v := range splitStr {

    if len(strings.Trim(v, " ")) >= 0{

    // some extra check

    if strings.Count(v, "\"") % 2 == 1 {

        fmt.Println( re.FindString(v))

    }


    } 

}

}


此處提供代碼示例: https: //play.golang.org/p/LYte6FRocv3


查看完整回答
反對 回復(fù) 2023-06-19
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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