# Pull values separately returned by regular expression

**URL:** <https://forums.powershell.org/t/pull-values-separately-returned-by-regular-expression/18896>\
**Category:** PowerShell Help\
**Created:** [March 24, 2022, 2:54pm UTC](https://forums.powershell.org/t/pull-values-separately-returned-by-regular-expression/18896 "2022-03-24T14:54:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rony1](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@rony1](https://forums.powershell.org/u/rony1)\
**Post date:** [March 24, 2022, 2:54pm UTC](https://forums.powershell.org/t/pull-values-separately-returned-by-regular-expression/18896/1 "2022-03-24T14:54:24Z")

</div>

In the Below script, the regular expression is returning the value “Environment\_Server Environment\_OTF Environment\_MPU” to the variable “$token\_name” (the value doesnt contain double quotes and includes spaces). Now, how can I pull each word seprately from the above value and print it? I mean, the above value contains 3 words, i want to print the 3 words one by one. Please help.

$num = 0  
$Count2 = 2  
while($num -le $Count2)  
{  
$token\_name = @([regex]::matches($line,$tokenrep)| sort| get-unique)  
$array\_list = $token\_name[$num -1]  
write-host “the values are” $array\_list  
$num = $num + 1  
}

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 24, 2022, 4:15pm UTC](https://forums.powershell.org/t/pull-values-separately-returned-by-regular-expression/18896/2 "2022-03-24T16:15:29Z")

</div>

When you post code, sample data, console output or error messages please format it as code using the _preformatted text_ button ( **\</\>** ). Simply place your cursor on an empty line, click the button and paste your code.  
Thanks in advance

> [@Welcome to the new PowerShell Forums](https://forums.powershell.org/t/welcome-to-the-new-powershell-forums/7/6):
>
> How to format code in [PowerShell.org](http://PowerShell.org) forums. [Codeformatting\_1]

> [@rony1](#):
>
> Now, how can I pull each word seprately from the above value

If I got it right you you use `-split` to split the input string at a certain character. In this case you could split it on the space character.

There might be a better of achieving what you need. You may elaborate a little more detailed what you want to do … the bigger picture …

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/pull-values-separately-returned-by-regular-expression/18896/3 "2024-05-16T20:18:09Z")

</div>


