[英]Regular expression to extract a string
我需要從一個大字符串中提取一個字符串。 是否可以使用正則表達式提取字符串:
4567 Test Assembling the Plant(4566) [2] WAST Testing1<CR><LF>
ERTW Test the second assembly [3] JEST Test4<CR><LF>
V345 This is another test (FAR X) [9] KERT Test192<CR><LF>
-- This is test Number 10 [6] <CR><lf>
Test100<CR><LF>
Number of the testing assembly (1234) Test the plant assembly <CR><LF>
V234 Testing the WIRE ASSEMBLY Test this assembly (12345-7876544) [9] <CR><LF>
C34567 This is another test assembly (123456) [6] trew43 This is test assembly<CR><LF>
RT234 Testing the assembly1100 PQR Testing assembly<CR><LF>
PL234 Test RET<CR><LF>
我可以使用正則表達式提取上述數據並將其插入數據庫中嗎
Table1
Col1 Col2 COL3 Col4
4567 Test Assembling the Plant(4566) [2] WAST Testing1
ERTW Test the second assembly [3] JEST Test4
V345 This is another test (FAR X) [9] KERT Test192
-- This is test Number 10 [6]
Number of the testing assembly (1234) Test the plant assembly
V234 Testing the WIRE ASSEMBLY Test this assembly (12345-7876544) [9]
C34567 This is another test assembly (123456) [6] trew43 This is test assembly
RT234 Testing the assembly1100 PQR Testing assembly
PL234 Test RET
是否可以使用正則表達式或基於列號提取以上內容。
任何幫助將不勝感激。
聽起來問題出在每個數據字段中有多個空格。 它們看起來像是單詞之間的單個空格,還是一個開孔前的多個空格(或[。因此,我將其轉換為單個空格,然后基於三個或更多空格將字段分開。然后我使用字段分隔符“ || “為清楚起見
cat file1 file2 | perl -pe 's/\s+\(/ \(/g;s/\s+\[/ \[/g' | perl -pe 's/\s{3,}/ \|\| /g' | perl -pe 's/<CR>.*//'
每行輸出看起來像這樣。 訂單僅基於貓。
是的,您可以使用Regex從大數據中提取字符串。 正則表達式的空格沒問題。
\\ s->任何空格字符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.