Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How can I recode a regular expression used to parse a string?

$
0
0

I want to code some parsing using regular expressions where I can later go in and change the suite of characters that I want to associate (or not associate) with a word-like entity.  In other words, I want to define what characters can be used to make up a word.  I coded the lines seen below, and it works pretty well except when my words get separated with more than one of the characters I define to not be ones that make up a word.  How can I recode this to treat a run of more than one of these characters to be the same as if there was only a single character separating two words?

<##> $s = 'a:b'<##> $s.split( '[' + '- @.":%&;,=~!`]}<>'+ [Regex]::Escape('\.+|$#[(){?^') + "'" + "`t" + ']+' )
a
b<##> $s = 'a::::b'<##> $s.split( '[' + '- @.":%&;,=~!`]}<>'+ [Regex]::Escape('\.+|$#[(){?^') + "'" + "`t" + ']+' )
a



b


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>