Even Expresso couldn't help me with this RegEx - Can You?
-
Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?
Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)
is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.
' Sample
[Track]
Latitude=N047° 25' 53.4256"
Longitude=W122° 18' 28.7933"
Altitude=+000432.00[Options]
Titles=False
Sound=True
Pause=FalseThank you very much in advance, Michael
-
Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?
Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)
is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.
' Sample
[Track]
Latitude=N047° 25' 53.4256"
Longitude=W122° 18' 28.7933"
Altitude=+000432.00[Options]
Titles=False
Sound=True
Pause=FalseThank you very much in advance, Michael
Michael, I guess something is wrong in your post, I see only one double quote, and no MultiLine option. You probably have a conflict with the HTML monster. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Michael, I guess something is wrong in your post, I see only one double quote, and no MultiLine option. You probably have a conflict with the HTML monster. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Happy day :-D! I could resolve a part of my regex task in Expresso. For the record and other users: Obviously ".*" for "any character / any number of repetitions" is not good enough to capture a CRLF! Trying to capture it with \r wasn't the right thing either, it took "\r\n" to match the group together with the first line! Here's the current status of the regex:
\[(?<Grp>.*)\]\r\n(?<Keyword>\w+)\s*=\s*(?<Value>.*)\r
The ultimate question would now be: Of course the first key-value-pair after the group header isn't enough. How can I include its repetitions into my match now? :confused: @ Luc: Thanks for the hint. I guess it was more a matter with my own attention monster ;) that I had here... @ Admin: Pls excuse me double-posting with the VB forum. This new forum obviously isn't too known yet, so that I had more forwarding answers there before being told to shift my post here...
-
Happy day :-D! I could resolve a part of my regex task in Expresso. For the record and other users: Obviously ".*" for "any character / any number of repetitions" is not good enough to capture a CRLF! Trying to capture it with \r wasn't the right thing either, it took "\r\n" to match the group together with the first line! Here's the current status of the regex:
\[(?<Grp>.*)\]\r\n(?<Keyword>\w+)\s*=\s*(?<Value>.*)\r
The ultimate question would now be: Of course the first key-value-pair after the group header isn't enough. How can I include its repetitions into my match now? :confused: @ Luc: Thanks for the hint. I guess it was more a matter with my own attention monster ;) that I had here... @ Admin: Pls excuse me double-posting with the VB forum. This new forum obviously isn't too known yet, so that I had more forwarding answers there before being told to shift my post here...
Michael, I'm not really a regex expert, but I would tackle your problem with two regex and two foreach; the first regex would locate groups, the second would parse the key=value pairs within a group. I've never seen this done with a single regex. BTW: I don't like your \r\n stuff at all. One normally uses the symbols for start-of-line (^) and end-of-lin ($)e, avoiding problems with matching things on the first line and last line (your input may or may not end on \r or \r\n). FYI: I have some similar regex stuff in my article CP Vanity[^] which scrapes some of the CodeProject web pages. Similiar meaning two regexes, two foreach loops. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?
Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)
is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.
' Sample
[Track]
Latitude=N047° 25' 53.4256"
Longitude=W122° 18' 28.7933"
Altitude=+000432.00[Options]
Titles=False
Sound=True
Pause=FalseThank you very much in advance, Michael
Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].
-
Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].
the OP started with a "Dim", in VB there is no escape mechanism AFAIK. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
the OP started with a "Dim", in VB there is no escape mechanism AFAIK. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
:doh: I need sleep. This working for eight hours a day sucks, why do people do it?
-
:doh: I need sleep. This working for eight hours a day sucks, why do people do it?
(fun)?$
-
Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].
Making tools to help with regular expressions must be fun, because I made one too. Looks kinda like yours. :)