mercredi 24 février 2021

Regex.Match returns different/wrong result in Unity compared to same exact code in a C# console app

I'm trying to get matches on a string in Unity using a Regular Expressions pattern. I've written the whole code inside a sample project and it worked perfectly fine.

tokens[line] = Regex.Matches(instructionLines[line], "^\\w*|(?<=q\\[)\\d*(?=\\]))";

I have validated that it matches what I need with regex101.

I have then printed out the result in my console, which was also correct.

Console App:
 h 0
 h 1
 h 2
 h 3
 cx 1 2
 t 1

Finally, I copy-pasted the code in Unity - and it doesn't match the first word of the line like it did in the sample project.

Unity Console:
 0
 1
 2
 3
 1 2
 1

I didn't change anything, the imports are the same (using System.Text.RegularExpressions;) and the regex is correct. Why does Unity do this, and how do I fix this incorrect behaviour?

Aucun commentaire:

Enregistrer un commentaire