Using Regex to parse string.

K

KK

Dear All
I have a string like this:
myOutput = myObject.MyMethod(myInput1,myInput2)
I would like to parse this string and separate it into 4 groups.
group1 contains left of '='.
group2 contains right of '=' and left of '.'
group3 contains right of '.' and left of '('...and so on.

I'm not expert in using Regular expressions.
Can some body help me how do I achieve this using Regex class?

Thanks a lot in advance.
Krishna Rao K Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex |
Guindy Industrial Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225
2273 / 76 , +91 98407 28998
 
L

Lasse Vågsæther Karlsen

KK said:
Dear All
I have a string like this:
myOutput = myObject.MyMethod(myInput1,myInput2)
I would like to parse this string and separate it into 4 groups.
group1 contains left of '='.
group2 contains right of '=' and left of '.'
group3 contains right of '.' and left of '('...and so on.

I'm not expert in using Regular expressions.
Can some body help me how do I achieve this using Regex class?

Thanks a lot in advance.
Krishna Rao K Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex |
Guindy Industrial Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225
2273 / 76 , +91 98407 28998

"^(?<g1>[^=]*)=(?<g2>[^.]*).(?<g3>.*)$"

This will give you three groups, g1 - g3, containing what you wanted.
This is a simplistic view of your criteria. If you need to automatically
strip out whitespace at the start/end of each group, you will need more
regex code.
 
K

KK

Thank you very much Mr.Karlsen

Lasse Vågsæther Karlsen said:
KK said:
Dear All
I have a string like this:
myOutput = myObject.MyMethod(myInput1,myInput2)
I would like to parse this string and separate it into 4 groups.
group1 contains left of '='.
group2 contains right of '=' and left of '.'
group3 contains right of '.' and left of '('...and so on.

I'm not expert in using Regular expressions.
Can some body help me how do I achieve this using Regex class?

Thanks a lot in advance.
Krishna Rao K Krishna Rao K Lucid Software Ltd 104, NSIC STP Complex |
Guindy Industrial Estate | Ekkattuthangal | Chennai 600032 ' +91 44 2225
2273 / 76 , +91 98407 28998

"^(?<g1>[^=]*)=(?<g2>[^.]*).(?<g3>.*)$"

This will give you three groups, g1 - g3, containing what you wanted. This
is a simplistic view of your criteria. If you need to automatically strip
out whitespace at the start/end of each group, you will need more regex
code.

--
Lasse Vågsæther Karlsen
mailto:[email protected]
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top