Search code examples
regexpowershell

Can't split string with regex


I want to split two sentences with 'apple' and 'apples' simultaneously. I try to use a regular expression 'apple*' or 'apple?'. But it doesn't work. I see the 's' in the second part of the second sentence. What's wrong with regex or split ?

$spl = '(apple*)'
'This apple for you','These apples for you' | % {$_ -split $spl}

enter image description here


Solution

  • $spl = 'apples?'
    'This apple for you', 'This apples for you' | ForEach-Object { $_ -split $spl }
    

    enter image description here