locked
Need Help With Regex RRS feed

  • Question

  • I need to read a registry and only keep everything after teh last "\"<o:p></o:p>

    And this was done by:<o:p></o:p>

    $addins = (Get-ChildItem –Path HKLM:\Software\Wow6432Node\Microsoft\Office\Outlook\Addins).name<o:p></o:p>

    $addins -creplace '(?s)^.*\\', ''

    With the help of google i was able to put together a regex string, but need some help understanding?

    Thank you



    • Edited by Ogeccut Tuesday, November 1, 2016 7:41 PM
    Tuesday, November 1, 2016 6:53 PM

Answers

  • Also, you don't need a regex. You can use Split-Path.


    PS C:\> Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Office\Outlook\Addins |
    Select-Object -ExpandProperty Name | Split-Path -Leaf
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Ogeccut Tuesday, November 1, 2016 7:44 PM
    Tuesday, November 1, 2016 7:06 PM

All replies

  • Please edit your post and remove the extraneous "<o:p>" and "</o:p>" HTML-like tags.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, November 1, 2016 7:04 PM
  • Also, you don't need a regex. You can use Split-Path.


    PS C:\> Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Office\Outlook\Addins |
    Select-Object -ExpandProperty Name | Split-Path -Leaf
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Ogeccut Tuesday, November 1, 2016 7:44 PM
    Tuesday, November 1, 2016 7:06 PM
  • Done, not sure why those were added.
    Tuesday, November 1, 2016 7:42 PM
  • Thank you, that works and much easier to read. 

    Would still like to understand regex if possible?

    Thank you.


    • Edited by Ogeccut Wednesday, November 2, 2016 4:35 PM
    Tuesday, November 1, 2016 7:44 PM
  • Please edit your post and remove the extraneous "<o:p>" and "</o:p>" HTML-like tags.

    -- Bill Stewart [Bill_Stewart]


    Those are the eyes of the Halloween Jack-O-Lantern.  He has invaded the server. 

    \_(ツ)_/


    • Edited by jrv Tuesday, November 1, 2016 8:10 PM
    Tuesday, November 1, 2016 8:10 PM
  • Teaching regex is a bit beyond the scope of this forum.

    However, it's not hard to find information, if you try.

    http://www.google.com/search?&q=learn+regular+expressions


    -- Bill Stewart [Bill_Stewart]

    Tuesday, November 1, 2016 8:13 PM
  • Here is a very good 5 part tutorial on RegEx with PowerShell: https://blogs.technet.microsoft.com/heyscriptingguy/2016/09/30/powershell-regex-crash-course-part-1-of-5/


    \_(ツ)_/

    Tuesday, November 1, 2016 8:23 PM