Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

tomy
Lv 4
tomy asked in 電腦與網際網路程式設計 · 1 decade ago

句子片段搜尋-使用(Regular Expression)

假設某文件中存在以下內容:

.... In Q2, sales dipped slightly from 7% to 6%. ....

... dipped greatly from ...

我想要查詢以dipped開頭,後頭跟著from的所有句子片段 (" dipped ... from ")

以上例來說,我想查到:

dipped slightly from

dipped greatly from

請問使用Regular Expression能做到這件事嗎?

如果可以的話,expression該怎麼寫呢?

謝謝!

2 Answers

Rating
  • 1 decade ago
    Favorite Answer

    我想,在 dipped 和 from 間的字元只會有小寫英文字和 space

    dipped‧[a-z‧]*from

    這樣應該就符合你的需求了

    Note : 為了怕你看漏 space,space 我用 ‧ 表示

    原 expression 要寫成 dipped [a-z ]*from 才對哦

    [a-z‧] 表示一個字元,可能是 a 至 z 其中一個或是 space

    * 表示前面的 [] 可以不存在或重覆1次以上

    不存在是 for 中間沒副詞修飾的情況,如: dipped from

    重覆1次以上表示之間可以有任意個英文字或 space

    Source(s): 最近有研究 regex
  • 1 decade ago

    以 dipped開頭,後頭跟著 from

    regex 可以寫成

    "dipped.*from"

    .* 表示中間有任何字元都可以

Still have questions? Get your answers by asking now.