正则表达式仅在第一个模式匹配后才匹配模式

时间:2019-10-11 15:57:24

标签: regex oracle plsql

我试图从仅IFF的字符串返回匹配项,而另一个模式在Oracle中首先使用from string import Template import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders MY_ADDRESS = 'myemail' def get_contacts(filename): names = [] emails = [] with open(filename, mode='r', encoding='utf-8') as contacts_file: for a_contact in contacts_file: names.append(a_contact.split()[0]) emails.append(a_contact.split()[1]) return names, emails def read_template(filename): with open(filename, 'r', encoding='utf-8') as template_file: template_file_content = template_file.read() return Template(template_file_content) def main(): names, emails = get_contacts('mycontacts.txt') # read contacts message_template = read_template('message.txt') # set up the SMTP server s = smtplib.SMTP(host='my.smpt.server') # s.starttls() #s.login(MY_ADDRESS, PASSWORD) # For each contact, send the email: for name, email in zip(names, emails): msg = MIMEMultipart() # create a message # add in the actual person name to the message template message = message_template.substitute(PERSON_NAME=name.title()) # Prints out the message body for our sake print(message) # setup the parameters of the message msg['From']=MY_ADDRESS msg['To']=email msg['Subject']="This is TEST" # add in the message body msg.attach(MIMEText(message, 'plain')) part = MIMEBase('application', "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") part.set_payload(open("my_filename.xlsx", "rb").read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="my_filename.xlsx"') msg.attach(part) # send the message via the server set up earlier. s.send_message(msg) del msg # Terminate the SMTP session and close the connection s.quit() if __name__ == '__main__': main() RegEx_Like进行匹配,但是结果却不尽相同。

下面是我拥有的数据以及我要从中返回的数据的示例:

+-----------------------------+---------+
|            Data             |  Goal   |
+-----------------------------+---------+
| 201301-P706466 JFK CLASSICS | P706466 |
| 201301-706466 WRI CLASSICS  | 706466  |
| 201301 706466 JFK CLASSICS  | 706466  |
| 201301 P706466 WRI CLASSICS | 706466  |
| 201910-MLB-CVG4             | NULL    |
| 201209-JFK CLASSICS         | NULL    |
| 201203-WRI CLASSICS         | NULL    |
| 201209 JFK CLASSICS         | NULL    |
| 201203 WRI CLASSICS         | NULL    |
+-----------------------------+---------+

查询:

RegExp_Substr

我尝试了this的不同变体,但是在regex101上,但是正如您将在导航到链接后所看到的那样,它比我所需要的要匹配得多。

我想我可能一起走错路了,这就是为什么我在这里。话虽如此,哪种模式最适合我的情况,并且最有效?

1 个答案:

答案 0 :(得分:2)

您可以使用此正则表达式来达到问题中提到的目标列:

(?=.*?(Apple))(?>.*?(Orange)

演示: Here