我從電子郵件中提取數據。我有這樣的文字:正則表達式/ preg_match - 獲取字符串和電子郵件地址之間的文本
Eg. 1: some standard text. Bugs Bunny [email protected] 0411111111 more standard text
Eg. 2: some standard text. Bugs The Bunny [email protected] 0411111111 more standard text
Eg. 3: some standard text. Bugs Bunny [email protected] 0411111111 more standard text
Eg. 4: some standard text. Bugs [email protected] +6141 111 111 more standard text
正如你所看到的,我想提取一個名字,電子郵件和電話號碼。 電子郵件應該很簡單,我確信我可以制定電話選項,但我怎麼能得到這個名字?
我知道的邏輯是:得到some standard text.
之後的文字和之前的第一個非空格分隔字符串@
之前,但是怎麼樣?
這是我的出發點(?<=some standard text. )(.*?)([email protected])
這給了我一個結果,與一羣(?<=some standard text. )(.*?)(?:[\w-\.]+)@
所以我覺得我在正確的道路上。
我正在使用php。
1.你是什麼意思用'全match'做? 2.那麼'一些標準文本.'總是相同的並且總是以點結束? – user
這裏是一個快速版本/我想出的例子:'(?<=一些標準文本。)(。*?)([^ \ s] + @ [^ \ s] +)(\ +?\ d +( ?:\ s \ d +)*)'(https://regex101.com/r/Wjz66g/1)。這並不完美,但它的確遵循了你所做的和可能足夠的工作。 –
@addons_zz - 我剛剛對羣體進行了自我教育,因此我將稍微修改這個問題。 – Warren