Hi all,
for the following string I want to search a pattern
The string is

lcpstr = "2008/03/25  log:true lcp: 78888 -> 100  lck=0 to=900 un=5840 l=0 BMN" 

If I take the pattern as "lcp: 78888", pattern checking is successful when I give the following statement:

temp = re.search("lcp:"+" "+'[0-9]+'+" ",lcpstr)
result = temp.group()
print  result

The output would be:

lcp: 78888

But I basically want to have the pattern to include the last part of the pattern ie "BMN". As it denotes the boundary of the string.
But if I give "->" in the pattern, the search is not succesfull.
ie if i give :

temp =  re.search("lcp:"+" "+'[0-9]+'+" "+"->"+" "+'[0-9]+'+"leq="+[0-9]+'+"lck=0 to=900 un=5840 l=0"+"BMN", lcpstr)
result = temp.group()
print result

then the search fails:
It says:

result = temp.group()
AttributeError: 'NoneType' object has no attribute 'group'

Please any one suggest me how to make the pattern string to have the last word ie "BMN" in it, as "BMN" is the bounadary marker for the string to be searched.

Regards,
Prashanth

A little verbose but see if it can help you.

import re

txt = '2008/03/25 log:true lcp: 78888 -> 100 lck=0 to=900 un=5840 l=0 BMN'

re1 = '.*?'	# Non-greedy match on filler
re2 = '(lcp)'	# Word 1
re3 = '(:)'	# Any Single Character 1
re4 = '(\\s+)'	# White Space 1
re5 = '(\\d)'	# Any Single Digit 1
re6 = '(\\d)'	# Any Single Digit 2
re7 = '(\\d)'	# Any Single Digit 3
re8 = '(\\d)'	# Any Single Digit 4
re9 = '.*?'	# Non-greedy match on filler
re10 = '(?:[a-z][a-z]+)'	# Uninteresting: word
re11 = '.*?'	# Non-greedy match on filler
re12 = '(?:[a-z][a-z]+)'	# Uninteresting: word
re13 = '.*?'	# Non-greedy match on filler
re14 = '(?:[a-z][a-z]+)'	# Uninteresting: word
re15 = '.*?'	# Non-greedy match on filler
re16 = '((?:[a-z][a-z]+))'	# Word 2

rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8+re9+re10+re11+re12+re13+re14+re15+re16,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
    word1 = m.group(1)
    c1 = m.group(2)
    ws1 = m.group(3)
    d1 = m.group(4)
    d2 = m.group(5)
    d3 = m.group(6)
    d4 = m.group(7)
    word2 = m.group(8)    
    w = word1 + c1 + ws1 + d1 + d2 + d3 + d4 + word2
    print w  #lcp: 7888BMN
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.