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

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

如何在Java中的String.contains()方法中使用正則表達(dá)式

如何在Java中的String.contains()方法中使用正則表達(dá)式

我想檢查一個(gè)字符串是否按順序包含單詞“ stores”,“ store”和“ product”。無論它們之間是什么。我嘗試使用someString.contains(stores%store%product);并且.contains("stores%store%product");我是否需要顯式聲明一個(gè)正則表達(dá)式并將其傳遞給方法,還是根本無法傳遞正則表達(dá)式?
查看完整描述

3 回答

?
瀟瀟雨雨

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

public static void main(String[] args) {

    String test = "something hear - to - find some to or tows";

    System.out.println("1.result: " + contains("- to -( \\w+) som", test, null));

    System.out.println("2.result: " + contains("- to -( \\w+) som", test, 5));

}

static boolean contains(String pattern, String text, Integer fromIndex){

    if(fromIndex != null && fromIndex < text.length())

        return Pattern.compile(pattern).matcher(text).find();


    return Pattern.compile(pattern).matcher(text).find();

}

1.結(jié)果:正確


2.結(jié)果:正確


查看完整回答
反對(duì) 回復(fù) 2019-10-30
  • 3 回答
  • 0 關(guān)注
  • 7682 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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