簡體   English   中英

正則表達式:捕獲行之間的文本,其中包括換行符,空格和下划線字符

[英]Regex Expression: Capture the Text Between the Lines which includes Newline, Spaces, And Underscore characters

我有一些文本取自pdf文件,並讀入了一個字符串:

...

Fabric Business Of the Cloths 

4 Description of the property being purchased 
______________________________________________________________________________

...

我想提取4 Description of the property being purchased的第4 Description of the property being purchased4 Description of the property being purchased之前的單詞,而不要提取其上方或下方的下划線。

我嘗試使用正則表達式/^[^4]*/但這返回null。

什么是實現上述目標的合適正則表達式?

謝謝。

您的regex表達式有效,只需刪除開頭和結尾的/。

    private void TestRegex()
    {
        string s = "...\n Fabric Business Of the Cloths\n                         4 Description of the property being purchased\n____________________________________________________________________________\n ...";
        Regex regex = new Regex("^[^4]*"); // <--- DO LIKE THIS, PERHAPS.
        //Regex regex = new Regex("/^[^4]*/"); <----NOT THIS
        Match match = regex.Match(s, 0);
        if (match.Success)
        {
            Console.WriteLine(match.Value);
        }
    }

輸出值

...
 Fabric Business Of the Cloths

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM