Skip to content

Examples for [Regex] #22

@B-Art

Description

@B-Art

Lets split by using replace: (I used = as a replacement so you will remember ;-))

[regex]::Replace('29 July, 2014, 30 July, 2014, 31 July, 2014,29 July, 2014, 30 July, 2014, 31 July, 2014','\s*([^,]+)(,\s*)([^,]+),*\s*', '$1 = $3'+"`n`r")
29 July = 2014
30 July = 2014
31 July = 2014
29 July = 2014
30 July = 2014
31 July = 2014

You can add labels to make it more readable:

[regex]::Replace('29 July, 2014, 30 July, 2014, 31 July, 2014,29 July, 2014, 30 July, 2014, 31 July, 2014','\s*(?<lbl1>[^,]+)(?<lbl2>,\s*)(?<lbl3>[^,]+),*\s*', '${lbl1} = ${lbl3}'+"`n`r")

If you make a typo you will notice this immediately:

[regex]::Replace('29 July, 2014, 30 July, 2014, 31 July, 2014,29 July, 2014, 30 July, 2014, 31 July, 2014','\s*(?<lbl1>[^,]+)(?<lbl2>,\s*)(?<lbl3>[^,]+),*\s*', '${lbl1} = ${lbl}'+"`n`r")
29 July = ${lbl}
30 July = ${lbl}
31 July = ${lbl}
29 July = ${lbl}
30 July = ${lbl}
31 July = ${lbl}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions