Reputation: 495
i have this very ridiculous string (see below) and want to strip it from all useless information.
I want to isolate all information that looks like that:
Deal: -139.8 | normal: 228.27 | new: 88.47 | CGN - BCN (Sep 25, Sep 27)
Numbers here can all be different, and so can the airport codes (CGN and BCN). The length of the string can also be different. Instead of just having
CGN - BCN (Sep 25, Sep 27)
in the end, there could be
CGN - BCN (Sep 25), BCN - NYC (Sep 27)
EDIT: How can I use a regex to isolate those information? I've started with [Deal\:\s\-]
to indicate that the string should start with this. Then I simply got lost. Since I am super new to regex and I did not know how to proceed from here
' ˇˇˇˇ304688Rv0OhVyeiV74 <>‘bD$æ⁄ Deal: -1811.28 | normal: 3158.15 | new: 1346.87 | TXL - NYC (Mar 18), NYC - ATL (Mar 24), ATL - MSY (Mar 30), MSY - TXL (Apr 02)UçÒˇˇˇ¸Uçıˇˇˇˇ304687 <>œ‘vh∞æ⁄ Deal: -319.59 | normal: 624.67 | new: 305.08 | SIN - DUS (Apr 28)UåÕºˇˇˇ¸UåÕøˇˇˇˇ303965lRaD7YP70KR+<[email protected]>œ‘ä√æ⁄ Deal: -319.52 | normal: 624.55 | new: 305.03 | SIN - DUS (Apr 28)UåÕ硡ˇ¸UåÕ롡ˇˇ303966s4Z+<[email protected]>œ‘ù€µæ⁄ Deal: -322.71 | normal: 627.58 | new: 304.87 | SIN - DUS (May 05)Uå¬zˇˇˇ¸Uå¬~ˇˇˇˇ304686 <[email protected]>’‘±êÕæ⁄ Deal: -139.8 | normal: 228.27 | new: 88.47 | CGN - BCN (Sep 25, Sep 27)UåÅØˇˇˇ¸UåÅ≤ˇˇˇˇ3039613//TlCzBs/<>œ‘≈]µæŸ Deal: -381.52 | normal: 732.66 | new: 351.14 | CGN - PEK (Aug 10)UåaGˇˇˇ¸UåaKˇˇˇˇ303962lWWb2SgeIy+<>œ‘Ÿ∏æŸ Deal: -148.04 | normal: 293.55 | new: 145.51 | BER - LPA (Oct 17)UåT!'
Upvotes: 0
Views: 52
Reputation: 67988
If the format is fixed ,you can use
\bDeal:.*?\([^|]*\)
and replace by empty string
.See demo.
https://regex101.com/r/fM9lY3/55
var re = /\bDeal:.*?\([^|]*\)/gm;
var str = '\' ˇˇˇˇ304688Rv0OhVyeiV74 <>‘bD$æ⁄ Deal: -1811.28 | normal: 3158.15 | new: 1346.87 | TXL - NYC (Mar 18), NYC - ATL (Mar 24), ATL - MSY (Mar 30), MSY - TXL (Apr 02)UçÒˇˇˇ¸Uçıˇˇˇˇ304687 <>œ‘vh∞æ⁄ Deal: -319.59 | normal: 624.67 | new: 305.08 | SIN - DUS (Apr 28)UåÕºˇˇˇ¸UåÕøˇˇˇˇ303965lRaD7YP70KR+<[email protected]>œ‘ä√æ⁄ Deal: -319.52 | normal: 624.55 | new: 305.03 | SIN - DUS (Apr 28)UåÕ硡ˇ¸UåÕ롡ˇˇ303966s4Z+<[email protected]>œ‘ù€µæ⁄ Deal: -322.71 | normal: 627.58 | new: 304.87 | SIN - DUS (May 05)Uå¬zˇˇˇ¸Uå¬~ˇˇˇˇ304686 <[email protected]>’‘±êÕæ⁄ Deal: -139.8 | normal: 228.27 | new: 88.47 | CGN - BCN (Sep 25, Sep 27)UåÅØˇˇˇ¸UåÅ≤ˇˇˇˇ3039613//TlCzBs/<>œ‘≈]µæŸ Deal: -381.52 | normal: 732.66 | new: 351.14 | CGN - PEK (Aug 10)UåaGˇˇˇ¸UåaKˇˇˇˇ303962lWWb2SgeIy+<>œ‘Ÿ∏æŸ Deal: -148.04 | normal: 293.55 | new: 145.51 | BER - LPA (Oct 17)UåT!\'';
var subst = '';
var result = str.replace(re, subst);
Upvotes: 1