2013-04-21 8 views
0

Я пытаюсь написать регулярное выражение, которое заменяет линейные каналы между определенными областями текстового файла, но только на определенные ключевые слова (начальное ключевое слово и ключевое слово end не сопряжены), но не имеют большой удачи в первой части.Регулярное выражение для замены строк с пробелом только в том случае, если разрыв находится в определенной ключевой паре

Пример входные данные:

QUESTION NO: 1130 

May a health plan require a provider to use a health care clearinghouse to conduct a HIPAA- covered transaction, or must the health plan acquire the ability to conduct the transaction directly with those providers capable of conducting direct transactions? 

A. A health plan may conduct its covered transactions through a clearinghouse, and may require a 
provider to conduct covered transactions with it through a clearinghouse. But the incremental cost of doing so must be borne by the health plan. It is a cost-benefit decision on the part of the health plan whether to acquire the ability to conduct HIPAA transactions directly with other entities, or to require use of a clearinghouse. B. A health plan may not conduct it's covered transactions through a clearinghouse 
C. A health plan may after taking specific permission from HIPAA authorities conduct its covered 
transactions through a clearinghouse D. is not as per HIPAA allowed to require provider to conduct covered transactions with it through 

a clearinghouse 

Answer: A 

Explanation: Personnel security always have to deal more with Operational controls, Operational 
controls provide the guidelines and the correct procedures to implement the different operations. Management controls are usually used only by managers. Human resources and Technical Controls are not related to personal security as the question states. See the different control definitions in your CISSP documentation. 

Пример вывод:

QUESTION NO: 1130 

May a health plan require a provider to use a health care clearinghouse to conduct a HIPAA- covered transaction, or must the health plan acquire the ability to conduct the transaction directly with those providers capable of conducting direct transactions? 

A. A health plan may conduct its covered transactions through a clearinghouse, and may require a provider to conduct covered transactions with it through a clearinghouse. But the incremental cost of doing so must be borne by the health plan. It is a cost-benefit decision on the part of the health plan whether to acquire the ability to conduct HIPAA transactions directly with other entities, or to require use of a clearinghouse. 
B. A health plan may not conduct it's covered transactions through a clearinghouse 
C. A health plan may after taking specific permission from HIPAA authorities conduct its covered transactions through a clearinghouse 
D. is not as per HIPAA allowed to require provider to conduct covered transactions with it through a clearinghouse 

Answer: A 

Explanation: A View is a display of one or more table shows that shows the table data. You can even retrieve part of the table and display the same to the user. Before a user is able to use a view, they must have both, permission on the view and all dependent objects. Views can also be used to implement security, for example you can create a view that only shows 3 of 5 columns contained in a table. Views are not used to provide integrity you can use constraints, rule or other components of database systems. 

Моя идеальная ситуация, содержание текста между "A. " и "Answer: " удаляются в новой строке и остальная часть текста сохранить нетронутыми.

+0

Какой язык вы используете? – HamZa

+0

@HamZaDzCyberDeV: Я лично использую Python/PHP/Javascript, но все, что работает в RegexBuddy, будет в порядке. – user1045217

ответ

0

В Python вы можете это сделать;

ВНИМАНИЕ: Это небезопасно полагаться на 100%. Если X. встречается в обычных предложениях, вы получите : be "screwed".

import re 

subject = '''A. A health plan may conduct its covered transactions through a clearinghouse, and may require a 
provider to conduct covered transactions with it through a clearinghouse. But the incremental cost of doing so must be borne by the health plan. It is a cost-benefit decision on the part of the health plan whether to acquire the ability to conduct HIPAA transactions directly with other entities, or to require use of a clearinghouse. B. A health plan may not conduct it's covered transactions through a clearinghouse 
C. A health plan may after taking specific permission from HIPAA authorities conduct its covered 
transactions through a clearinghouse D. is not as per HIPAA allowed to require provider to conduct covered transactions with it through''' 

result = re.findall(r'([A-Z]\.)(.*?)(?=[A-Z]\. |$)', subject, re.S) 

new_string = '' 

if len(result) > 0: 
    for entry in result: 
     new_string += entry[0] + entry[1].strip().replace('\n', ' ') + '\n' 
else: 
    print 'Nothing found' 

print new_string 

Положительное опережение ищет либо новый X. или конец строки. Это может не работать, если вы соответствуете всей строке. В этом случае пусть он продолжит искать до тех пор, пока не найдет Answer: и полосу задней строки новой строки ((?=[A-Z]\. |\n+Answer: \w)).

терминал Выходной

iMac2011:Desktop allendar$ python test.py 
A. A health plan may conduct its covered transactions through a clearinghouse, and may require a provider to conduct covered transactions with it through a clearinghouse. But the incremental cost of doing so must be borne by the health plan. It is a cost-benefit decision on the part of the health plan whether to acquire the ability to conduct HIPAA transactions directly with other entities, or to require use of a clearinghouse. 
B. A health plan may not conduct it's covered transactions through a clearinghouse 
C. A health plan may after taking specific permission from HIPAA authorities conduct its covered transactions through a clearinghouse 
D. is not as per HIPAA allowed to require provider to conduct covered transactions with it through 

Обновить код

import re 

subject = '''QUESTION NO: 1130 

May a health plan require a provider to use a health care clearinghouse to conduct a HIPAA- covered transaction, or must the health plan acquire the ability to conduct the transaction directly with those providers capable of conducting direct transactions? 

A. A health plan may conduct its covered transactions through a clearinghouse, and may require a 
provider to conduct covered transactions with it through a clearinghouse. But the incremental cost of doing so must be borne by the health plan. It is a cost-benefit decision on the part of the health plan whether to acquire the ability to conduct HIPAA transactions directly with other entities, or to require use of a clearinghouse. B. A health plan may not conduct it's covered transactions through a clearinghouse 
C. A health plan may after taking specific permission from HIPAA authorities conduct its covered 
transactions through a clearinghouse D. is not as per HIPAA allowed to require provider to conduct covered transactions with it through 

a clearinghouse 

Answer: A 

Explanation: Personnel security always have to deal more with Operational controls, Operational 
controls provide the guidelines and the correct procedures to implement the different operations. Management controls are usually used only by managers. Human resources and Technical Controls are not related to personal security as the question states. See the different control definitions in your CISSP documentation.''' 

result = re.findall(r'([A-Z]\.)(.*?)(?=[A-Z]\. |\n{1,}Answer:\s\w+\s?\n+)', subject, re.S) 


new_string = '' 

if len(result) > 0: 
    for entry in result: 
     new_string += entry[0] + entry[1].strip().replace('\n\n', ' ').replace('\n', ' ') + '\n' 
else: 
    print 'Nothing found' 

print new_string 
+0

Частично работает, но у меня есть сбой в «Объяснение». Текст примера выше изменен. – user1045217

+0

Попробуйте обновленный код. Я не то, что вы имеете в виду под «измененным». Вы имеете в виду мое собственное редактирование образца регулярного выражения ('(? = [A-Z] \. | \ N {2,} Ответить | \ n + Ответить: \ w)')? – 2013-04-22 06:15:14