By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Regex Text parsing

P: n/a
Hi,

I am trying to write a text parser to group all nonprintable and
control characters, spaces and space delimited words in different
groups using Regex class. Using a parsing of (?<Commands>[
\x00-\x1f\x7f-\xfe])|(?<Spaces>[ \x20])|(?<Text>[ \x21-\x7e]+) on my
sample text of \tOne\ncar red \fcar\a blue car\r\n \r\n does not work
as indetended. Specially, the spaces are grouped as commands and the
Text grouping ends up grouping words delimited by spaces. Here is the
sample output:

Found Command = 0x9
Found Text = One
Found Command = 0xA
Found Text = car red
Found Command = 0xC
Found Text = car
Found Command = 0x7
Found Command = 0x20
Found Text = blue ca
Found Command = 0xD
Found Command = 0xA
Found Command = 0x20
Found Command = 0xD
Found Command = 0xA

As you can see, the spaces are found in the 2nd text group found (car
red) as well as the last text group. Spaces also appear in the command
group (0x20 is the hex code for a space). What is the correct parsing
string to achieve what I am looking for?

Thanks,
Jay

Apr 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
There's a space in your <Text> group (Just before "\x21"):

(?<Text>[ \x21-\x7e]+)

... should be

(?<Text>[\x21-\x7e]+)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

<Ja*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Hi,

I am trying to write a text parser to group all nonprintable and
control characters, spaces and space delimited words in different
groups using Regex class. Using a parsing of (?<Commands>[
\x00-\x1f\x7f-\xfe])|(?<Spaces>[ \x20])|(?<Text>[ \x21-\x7e]+) on my
sample text of \tOne\ncar red \fcar\a blue car\r\n \r\n does not work
as indetended. Specially, the spaces are grouped as commands and the
Text grouping ends up grouping words delimited by spaces. Here is the
sample output:

Found Command = 0x9
Found Text = One
Found Command = 0xA
Found Text = car red
Found Command = 0xC
Found Text = car
Found Command = 0x7
Found Command = 0x20
Found Text = blue ca
Found Command = 0xD
Found Command = 0xA
Found Command = 0x20
Found Command = 0xD
Found Command = 0xA

As you can see, the spaces are found in the 2nd text group found (car
red) as well as the last text group. Spaces also appear in the command
group (0x20 is the hex code for a space). What is the correct parsing
string to achieve what I am looking for?

Thanks,
Jay

Apr 28 '06 #2

P: n/a
Jay
Thanks Kevin! That was it!

Apr 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.