|
List Info
Thread: Parsing a line using RE
|
|
| Parsing a line using RE |

|
2006-04-14 00:16:01 |
Hello all,
I am attempting to create a small scripting application to
be used
during testing. I was going to extract the commands from a
script file
via tokenizing the each line at a time in order to parse the
command. I
have always wanted to learn Regular Expressions, so I was
hoping I
might do this using Regular Expressions. For a fair number
of the
commands they will have the following syntax similar to
Write( 0x123, 0x12, 25, 100 ) <- Write three bytes to
address 0x123
Write(varName1, 0x12) <- Write one bytes to
address
expressed by the value
of
varName1
Read( 0x55, 5 ) <- Write one bytes to
address 0x55
Read(0x3456, 0x12) <- Read eighteen bytes
to address
0x3456
varName2 = Read( varName1 ) <- Read one byte from
address
expressed by the value
of varName1
and store that read
value to
varName2
I know if I use the regular expression (^[a-zA-Z]*) will
find the
initial keywords or variable names which I can perform an
initial check
to make sure they are valid or the variable has been
declared already,
but the hard part is creating a regular expression to match
the various
forms of the syntax. Based upon the initial symbol found I
could use
various regular expression to extract each field/argument
from the
command.
My question is wow would I create a regular express for the
first and
last script commands? I think with those I can attempt to
determine the
others. The spaces between the arguments are optional and
may be
omitted if the user so desires.
For the first script command I was attempting to craft one
that looks
like..
(^[a-zA-Z]*)('\(')(['0x',0-9][a-zA-Z]*)(',')(['0x',
0-9][a-zA-Z]*)
but this obviously doesn't work. Any help is greatly
appreciated.
Mark
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 06:04:11 |
to validate format and to caprure all 4 parameters as the
capturing
group 1 (\d[x\d]*) in
Write( 0x123, 0x12, 25, 100 )
u can try regex
write\s*\((?:(?:\s*(\d[x\d]*)\s*)|(?:,))+\)
[SingleLine ON]
i tested it OK in http://rereplace.com. The
regex makes sure a
parameter starts with a digit and could have 'x' at
position >1
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 06:08:45 |
to validate format and to capture varname1 and varname2 from
statement
varName2 = Read( varName1 )
use regex
([a-z]\w*)\s*=\s*read\s*\(\s*([a-z]\w*)\s*\)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 06:26:14 |
regex
write\s*\((?:(?:\s*(\d[x\d]*)\s*)|(?:,))+\)
will give u 1 match : the whole expression u r validating
the match will include 1 capturing group: (\d[x\d]*) that
will
contain 4 (an possibly more) captures.
U'll need to access those 4 captures to retrieve the data
for
parameters values
If u cannot do it in your environment, thne the regex needs
to be
rewritten. Let me know
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 06:48:11 |
instead of
write\s*\((?:(?:\s*(\d[x\d]*)\s*)|(?:,))+\)
use
write\s*\((?:\s*(\d[x\d]*)\s*,?)+\)
to validate
Write( 0x123, 0x12, 25, 100 )
grouping stays the same : 4 captures in one capturing group
1 :
(\d[x\d]*)
captures: 0x123 0x12 25 100
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 10:47:12 |
Sergei Z wrote:
> instead of
> write\s*\((?:(?:\s*(\d[x\d]*)\s*)|(?:,))+\)
> use
> write\s*\((?:\s*(\d[x\d]*)\s*,?)+\)
>
> to validate
> Write( 0x123, 0x12, 25, 100 )
>
> grouping stays the same : 4 captures in one capturing
group 1 :
> (\d[x\d]*)
> captures: 0x123 0x12 25 100
Sergei Z,
Thanks for all the great help thus far. I will give these
a try in
the morning and see what I can get them to work. Not sure if
it really
matters, but I am using C# and using the RegEx class.
Mark
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 15:05:10 |
RE *Not
sure if it really
matters, but I am using C# and using the RegEx class.**
it does: that's what i'm using
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
| Parsing a line using RE |

|
2006-04-14 15:21:32 |
try to break them w/ invalid input: i suspect they r still
breakable.
If so, we'll rewrite them. let me know.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|
|
[1-8]
|
|