Regex: opcional-ignorar comillas dobles
Frecuentes
Visto 592 veces
0
Hello I have a question about matching groups based on the following regular expression
static string partPattern = @"^(?<Key>\w+)\s*(?<Value>.*)$";
Sample Data as following:
TEST_REPLICATE
{
REPLICATE_ID 1986
ASSAY_NUMBER 877
ASSAY_VERSION 4
ASSAY_STATUS "Research"
}
I am able to retrieve values correctly and if values are NULL, it works correctly as well. What I am trying to do is to also retrieve a value for instance the last one module which is in double quotes. I am not really sure if i am doing it correctly, would this be the correct regex for the above scenario, I just added quotes before w. Please correct, thanks
static string partPattern = @"^(?<Key>\"w+)\s*(?<Value>.*)$";
2 Respuestas
1
You regex is not correct.Atleast for the input you have provided..
If I have understood your question,this is the regex that you need.
^\s*(?<Key>\w+)\s*\"?(?<Value>.*?)\"?$
funcionaría con multiline
modo...
Respondido el 06 de Septiembre de 12 a las 16:09
0
Not sure where your problem is. This works for me:
\s*(?<Key>[^\s]+)\s*(?<Value>.*)
Respondido el 06 de Septiembre de 12 a las 16:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# regex or haz tu propia pregunta.
Doesn't your original expression already match such values? - Qtax
You want quotes stripped from value? - BlueM
@Qtax, You are right it works, the existing regex works too, i just didnt have the node in it ,thanks!!! - user721