seach for pattern based on string

R

richie05 bal

i am starting to learn python and I am stuck with query I want to
generate with python
File looks something like this
TRACE: AddNewBookD {bookId 20, noofBooks 6576, authorId 41,
publishingCompanyId 7}
TRACE: AddNewBookD {bookId 21, noofBooks 6577, authorId 42,
publishingCompanyId 8}

I want to first search for AddNewBookD
if found
store bookId, noofBooks, authorId and publishingCompanyId

I know how to search for only AddNewBookD or find the pattern bookId
20, noofBooks 6576, authorId 41, publishingCompanyId 7 but I don't
know how search one based on another.
 
A

Alex Willmer

i am starting to learn python and I am stuck with query I want to
generate with python
File looks something like this
TRACE: AddNewBookD {bookId 20, noofBooks 6576, authorId 41,
publishingCompanyId 7}
TRACE: AddNewBookD {bookId 21, noofBooks 6577, authorId 42,
publishingCompanyId 8}

I want to first search for AddNewBookD
if found
   store bookId, noofBooks, authorId and publishingCompanyId

I know how to search for only AddNewBookD or find the pattern bookId
20, noofBooks 6576, authorId 41, publishingCompanyId 7 but I don't
know how search one based on another.

Using a regular expression I would perform a match against each line.
If the match fails, it will return None. If the match succeeds it
returns a match object with which you can extract the values

So your code to store the result would be inside an if m: block

HTH, Alex
 
R

richie05 bal

Using a regular expression I would perform a match against each line.
If the match fails, it will return None. If the match succeeds it
returns a match object with which you can extract the values


('20', '6576', '41', '7')



So your code to store the result would be inside an if m: block

HTH, Alex

thanks Alex. exactly what i was looking for.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top