Regex - Matching text AFTER certain characters

后端 未结 4 1470
梦如初夏
梦如初夏 2020-12-19 01:15

I want to scrape data from some text and dump it into an array. Consider the following text as example data:

| Example Data
| Title: This is a sample title
|         


        
4条回答
  •  我在风中等你
    2020-12-19 01:36

    In Ruby, as in PCRE and Boost, you may make use of the \K match reset operator:

    \K keeps the text matched so far out of the overall regex match. h\Kd matches only the second d in adhd.

    So, you may use

    /:[[:blank:]]*\K.+/     # To only match horizontal whitespaces with `[[:blank:]]`
    /:\s*\K.+/              # To match any whitespace with `\s`
    

    Seee the Rubular demo #1 and the Rubular demo #2 and

    Details

    • : - a colon
    • [[:blank:]]* - 0 or more horizontal whitespace chars
    • \K - match reset operator discarding the text matched so far from the overall match memory buffer
    • .+ - matches and consumes any 1 or more chars other than line break chars (use /m modifier to match any chars including line break chars).

提交回复
热议问题