Use Regex in C# to insert spaces between ConcatenatedFileNamesLikeThis?

前端 未结 2 1032
再見小時候
再見小時候 2021-01-06 04:31

We\'re trying to generate user friendly looking report names from SSRS Report filenames, these can\'t have spaces in the name but it should be possible to generate them from

相关标签:
2条回答
  • 2021-01-06 05:11

    Edit 2 fixed IEE

    var input = @"WeeklyIEEReportWC20090103SortedByDate";
    string p = @"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z0-9])(?=[A-Z])|(?<=[a-zA-Z])(?=[0-9])";
    string value = Regex.Replace(input, p, " ");
    

    produces Members Of IEE Team and Weekly IEE Report WC 20090103 Sorted By Date for the samples provided.

    0 讨论(0)
  • 2021-01-06 05:25

    My interpretation and solution:

    var input = "WeeklyIEEReportWC20090103SortedByDateXFoo3W3CBar4x";
    var re = @"(?!^)(?:[A-Z](?:[a-z]+|(?:[A-Z\d](?![a-z]))*)|\d+)";
    string value = Regex.Replace(input, re, " $0");
    

    Result: Weekly IEE Report WC20090103 Sorted By Date X Foo 3 W3C Bar 4x

    0 讨论(0)
提交回复
热议问题