नोटपैड ++ का उपयोग करके दस्तावेज़ से विशिष्ट पाठ निकालें


0

मेरे पास एक पाठ फ़ाइल है जिसे मुझे विशिष्ट डेटा तत्वों को निकालने की आवश्यकता है।

उदाहरण पाठ:

<url>
    <loc>https://example.com/example0.html</loc>
    <lastmod>2019-01-22</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example1.html</loc>
    <lastmod>2019-01-21</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example2.html</loc>
    <lastmod>2019-01-21</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example3.html</loc>
    <lastmod>2019-01-20</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example4.html</loc>
    <lastmod>2019-01-20</lastmod>
    <priority>0.5</priority>
</url>

मैं निकालना चाहता हूं:

https://example.com/example0.html
https://example.com/example1.html
https://example.com/example2.html
https://example.com/example3.html
https://example.com/example4.html

कृपया ध्यान रखें कि तिथि स्थिर नहीं है


"अर्क" से आपका क्या तात्पर्य है? क्या आप सब कुछ हटाना चाहते हैं लेकिन URL?
— टोटो

जवाबों:


0
  • Ctrl+H
  • क्या ढूँडो: <url>\s+<loc>(\S+?)</loc>.+?</url>
  • से बदलो: $1
  • चारों ओर लपेटें की जाँच करें
  • नियमित अभिव्यक्ति की जाँच करें
  • चेक . matches newline
  • Replace all

स्पष्टीकरण:

<url>       # literally
  \s+       # 1 or more any spaces, including linebreak
  <loc>     # literally
  (\S+?)    # group 1, 1 or more non spaces, not greedy
  </loc>    # literally
  .+?       # 1 or more any characters, not greedy
</url>      # literally

रिप्लेसमेंट:

$1          # content of group 1, the URL

दिए गए उदाहरण के लिए परिणाम:

https://example.com/example0.html
https://example.com/example1.html
https://example.com/example2.html
https://example.com/example3.html
https://example.com/example4.html

1

एक सरल तरीका हो सकता है, और मेरे पास अभी नोटपैड ++ तक पहुंच नहीं है, लेकिन आप निम्नलिखित की कोशिश कर सकते हैं

खोज: <url>\n\s+<loc>(.*)<\/loc>\n\s.*\n\s.*\n<\/url>

बदलने के: \1

स्रोत regexr.com/46rin


अफसोस की बात है, यह त्रुटि संदेश काम नहीं किया: कोई घटना नहीं मिली
— kraus क्रिस्टोफर
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.