0

我正在尝试编写一个正则表达式来替换文本文件某些区域之间的换行符,但仅限于某些关键字(开始关键字和结束关键字未配对),但在第一部分之后运气不佳。

示例输入:

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: "删除,其余文本保持不变。

4

1 回答 1

0

在 Python 中你可以这样做;

警告:100% 依赖是不安全的。如果X.出现在正常的句子中,你被“搞砸”。

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
于 2013-04-21T17:29:47.977 回答