Clarification on Regex backtracking and positive lookbehinds in C#?
I'm working with SQL strings that will have multiple unique identifiers inside them. I need to read through the string, find each identifier, and assign an ID to it so that I can put it into a dictionary for reference later. Here's an example of what I'm working with:
SELECT * FROM Table WHERE SC = <<SC>> and SE = <<SE>>
At the moment, I'm searching the string for these identifiers with the following regex:
(?s)(?<=<<).*?(?=>>)
Using this article, I learned that the Regex engine I'm using is an NFA engine, and that if I want to disable backtracking and force the string to be processed deterministically, I should add the (?>) modifier to my expression. The expression I'm using above is working in that I am getting an array of my identifiers, but I need to guarantee that I'm doing so in a predictable, deterministic fashion.
I believe if I'm reading this sub-article correctly, adding the positive look-behind won't introduce backtracking, and will leave the expression to run deterministically
If my code processes that string the first time as ["SC": 1, "SE": 2], will the expression I currently have always return those same values, or will it sometimes process the string as ["SE": 1, "SC": 2]?
0 comments:
Post a Comment