Regular expression to find separator dots in formula

前端 未结 2 1311
南方客
南方客 2021-01-20 23:59

The C# expression library I am using will not directly support my table/field parameter syntax:

The following are table/field parameter names that are not directly suppo

相关标签:
2条回答
  • 2021-01-21 00:39

    I've written a completely new answer, now that the problem is clarified:

    You can do this in a single regex. It is quite bulletproof, I think, but as you can see, it's not exactly self-explanatory, which is why I've commented it liberally. Hope it makes sense.

    You're lucky that .NET allows re-use of named capturing groups, otherwise you would have had to do this in several steps.

    resultString = Regex.Replace(subjectString, 
        @"(?:             # Either match...
         (?<before>       #  (and capture into backref <before>)
          (?=\w*\p{L})    #  (as long as it contains at least one letter):
          \w+             #  one or more alphanumeric characters,
         )                #  (End of capturing group <before>).
         \.               #  then a literal dot,
         (?<after>        #  (now capture again, into backref <after>)
          (?=\w*\p{L})    #  (as long as it contains at least one letter):
          \w+             #  one or more alphanumeric characters.
         )                #  (End of capturing group <after>) and end of match.
        |                 # Or:
         \[               #  Match a literal [
         (?<before>       #  (now capture into backref <before>)
          [^\]]+          #  one or more characters except ]
         )                #  (End of capturing group <before>).
         \]\.\[           #  Match literal ].[
         (?<after>        #  (capture into backref <after>)
          [^\]]+          #  one or more characters except ]
         )                #  (End of capturing group <after>).
         \]               #  Match a literal ]
        )                 # End of alternation. The match is now finished, but
        (?=               # only if the rest of the line matches either...
         [^']*$           #  only non-quote characters
         |                # or
         [^']*'[^']*'     #  contains an even number of quote characters
         [^']*            #  plus any number of non-quote characters
         $                #  until the end of the line.
        )                 # End of the lookahead assertion.", 
        "[${before}|${after}]", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
    
    0 讨论(0)
  • 2021-01-21 00:46

    hope that you can try this regex: /(\w[0-9]* *)+/g this filters out all the alphanumerical except for the .

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