#Select-String Pattern Matching

23 messages · Page 1 of 1 (latest)

quaint stream
#

I am trying to use the Select-String Cmdlet to get all lines between the --- markers. Here's an example file:

---
layout: layouts/blog.njk
title: "Post #1"
date: "2022-01-03"
author: Stefan Greve
description: Simple test description which serves as a summary of this whole article.
headers: ["Header 1", "Header 2", "Header 3", "Header 4"]
latex: true
status: private
---

<h2 id="header-1">Header 1</h2>

<p>
  This is just a small test post for {{ title }} with some <code>print('test')</code> code.
</p>

I have used this regex tester site to test the pattern ---(\n|.)*?--- (which works with the .NET flavor). But when I use the pattern in PowerShell,

$Content = Select-String -Path $p -Pattern "---(\n|.)*?---" -AllMatches

it doesn't work. Any ideas why this could be the case? Regex isn't really my strong suit... notlikethiscat

regex101

Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

timber knot
#

"simpler" pattern:

^---\n([\s\S]*?)^---

should do

quaint stream
timber knot
quaint stream
timber knot
#

one could invest the time ... but as long there is more possibilities - nn to fiddle around i guess 🙂

quaint stream
#

true, this was also the last missing piece for my rss feed builder, so I'm done with this now :D

timber knot
#

parse "static" sites/posts to feed? or whats the idea?

quaint stream
#

it's a small blog built with nunjucks (a JS templating engine), which builds the project as static single pages, for which I wanted to create a RSS feed as well, so using PowerShell seemed like a good idea for me

timber knot
#

depends - possible for sure - personally would focus something "web-born" - aka php/py - something you could literally run on your webserver - so the script output will be the feed literally

#

not used to nunjucks - but if the content is structured: should be possible aswell to create a rss-formatted output aswell i guess

#

just ideas 🙂 / feedback - do as you feel like

quaint stream
#

much appreciated

timber knot
#

personally just love wordpress for anything web - even if you dont use the php frontend at all // simple to add structured data - feed is around / rest api on content is around

#

A pack of plugins for generating an RSS feed (actually an Atom feed, but who’s counting) using the Nunjucks templating engine

fervent perch
solar quail
#
$doc[1]
<h2 id="header-1">Header 1</h2>
<p> This is just a small test post for {{ title }} with some <code>print('test')</code> code. </p>
fervent perch