fork download
  1. import re
  2. def process_PartNo(text):
  3. return re.sub(r'(?:PartNoId\s+)?(PartNo-)', r'PartNoId \1', text, flags=re.I)
  4. #######################################################################################
  5. text1 = 'PartNo-001A description 20 units some other description'
  6. text2 = 'PartNoId PartNo-001A description QtyOrd 20 some other description'
  7. text3 = '''
  8. PartNoId
  9. PartNo-001A description QtyOrd 20'
  10. '''
  11. text4 = '''
  12. PartNoId
  13.  
  14. PartNo-001A description QtyOrd 20'
  15. '''
  16. text5 = '''
  17. PartNoId PartNo-001A description QtyOrd 20 some other description
  18. PartNoId PartNo-002A description QtyOrd 20 some other description
  19. '''
  20. text6 = '''
  21. PartNo-001A description QtyOrd 20 some other description
  22. PartNo-002A description QtyOrd 20 some other description
  23. '''
  24. ###########################################################################
  25. print(process_PartNo(text1))
  26. print(process_PartNo(text2))
  27. print(process_PartNo(text3))
  28. print(process_PartNo(text4))
  29. print(process_PartNo(text5))
  30. print(process_PartNo(text6))
Success #stdin #stdout 0.02s 9704KB
stdin
Standard input is empty
stdout
PartNoId PartNo-001A description 20 units some other description
PartNoId PartNo-001A description QtyOrd 20 some other description

PartNoId PartNo-001A description QtyOrd 20'


PartNoId PartNo-001A description QtyOrd 20'

 
PartNoId PartNo-001A description QtyOrd 20 some other description
PartNoId PartNo-002A description QtyOrd 20 some other description 

 
PartNoId PartNo-001A description QtyOrd 20 some other description
PartNoId PartNo-002A description QtyOrd 20 some other description