Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
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?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The issue was fixed thanks to @Thefourthbird, to quote from comments:

Try it adding multiline (?m)^[a-z]|(?<=q[)\d(?=])

In the link you added to your question regex101.com/r/FzpZXq/1 you can see at the right top that there is an m flag for multiline. As your pattern uses an anchor ^ you have to enable multiline, which can also be done using an inline modifier (?m) See regular-expressions.info/anchors.html

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda