List Info

Thread: Checking syntax and capturing the groups correctly




Checking syntax and capturing the groups correctly
country flaguser name
United States
2007-05-22 11:18:52
Hello all,

  I need to check the syntax of the following

DataLog(0x22,Int,0x23 + 0x44,Int,0x24,Int,0x55,Octal,33 +
4,Hex)

I have the following RegEx for this which is

^s*DataLogs*(s*(?:(?:(d+|0x[da-fA-F]+|[_a-zaA-Z][d_a-
zaA-Z]*)
s*(?:([+-])s*(d+|0x[dA-Fa-f]+)){0,1}s*,s*(UByte|UShor
t|UInt|
Byte|Short|Int|Float|Hex|Binaryctal))(?:
s*,s*(d+|0x[da-fA-F]+|
[_a-zaA-Z][d_a-zaA-Z]*)s*(?:([+-])s*(d+|0x[dA-Fa-f]+))
{0,1}s*,
s*(UByte|UShort|UInt|Byte|Short|Int|Float|Hex|Binaryctal)s*)
*)
{0,1}s*)s*$

Which will work fine, so long as I am checking my syntax,
but it fails
at capturing the "+ 0x44" and "+ 4"
which will be captured under group
6 and group 7.  If I run the RegEx against this input I will
get the
following groups (omitting groups 1 to 4)

Group 5
  Capture '0x23'
  Capture '0x24'
  Capture '0x55'
  Capture '33'
Group 6
  Capture '+'
  Capture '+'
Group 7
  Capture '0x44'
  Capture '4'
Group 8
  Capture 'Int'
  Capture 'Int'
  Capture 'Octal'
  Capture 'Hex'

My problem is that the items in Group 6 and Group 7 do not
properly
align themselves to groups 5 and 8. Currently, I am at a
lost on how
to create a RegEx that will capture and align all the
elements
(correct term?) correctly. Right now, I am forced to run
this RegEx
just to check the syntax of the statement, then run the
following
RegEx just to capture the groupings correctly..

s*(?:s*(d+|0x[da-fA-F]+|[_a-zaA-Z][d_a-zaA-Z]*)s*(?:([
+-])s*(d
+|0x[dA-Fa-f]+)){0,1}s*,s*(UByte|UShort|UInt|Byte|Short|I
nt|Float|
Hex|Binaryctal)s*)


I would like to create one RegEx that will check the syntax
and group
everything correctly. Is there a way to do this that I am
missing?

Mark


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )