Reputation: 53
My problem is that if I write $var -match "(id="".*?$args)"
, I get everything from the first id
of the text to $args
, but I only need text starting from the id
which is closest to $args
.
Any help would be much appreciated.
Upvotes: 1
Views: 81
Reputation: 336
Assuming $var
has no properties we can grab, if so just use select
/where
, otherwise what you can try is finding the start index of $args
, then if the IDs are the same length each time you could grab X number of characters before $args.
#So it would look something like: ID=xxxxxx$args
$argsIndex = $var.IndexOf($args)
#Lets say the ID is always 6 chars long, grab 6 characters prior using the substring method:
$var.substring($argsIndex-6,6)
Upvotes: 1