简体   繁体   中英

Extracting interested part of a string between '\' using regex

I have the string '[)>\x1E12\x1DMFR P0540\x1DPNR XY30357\x1DSER PPQRW599999901\x1E\x04' and would like to use regex to extract data from the string of particular interest as listed below:

  1. MFR P0540
  2. PNR XY30357
  3. SER PPQRW599999901

EDIT: You didn't write right away that it's Python, but I leave it to someone maybe useful.

Use GAWK if possible:

echo '[)>\x1E12\x1DMFR P0540\x1DPNR XY30357\x1DSER PPQRW599999901\x1E\x04' |gawk -v RS="x1D" '/[A-Z]{3} /{split($0,s,"\\"); print s[1]}'

result:

MFR P0540
PNR XY30357
SER PPQRW599999901

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM