Home > Mobile >  JavaScript Delete String starts with ... sort netscape cookie
JavaScript Delete String starts with ... sort netscape cookie

Time:10-31

i have cookie file netscape format in txt file (cookie.txt)

string like this:

*

www.googleadservices.com    FALSE   /pagead/conversion/978707571/   FALSE   1627665641  Conversion  EgwIABUAAAAAHQAAAAAYASD4pcHu056z1PkBSAFqN0VBSWFJUW9iQ2hNSWdyMlhwdi1vOEFJVjBGVmdDaDFXMlFJQkVBQVlBU0FCRWdLc05QRF9Cd0Vwid7vlf-o8AKQAdrswpmZDJgBAA
.google.com TRUE    /chrome FALSE   1682961684  _ga GA1.2-2.550592729.1619889685
.chrome.google.com  TRUE    /   FALSE   1682961841  __utma  73091649.1935727784.1619889805.1619889805.1619889805.1
.zenmate.com    TRUE    /   FALSE   1652018810  browser_session 
.zenmate.com    TRUE    /   FALSE   1682961844  _ga GA1.2.1460173919.1619889844
widget-mediator.zopim.com   FALSE   /   FALSE   1620494646  AWSALBCORS  7gqxWm82xyFUcYX0r49OUTaI5iBKtuLHeAvuIq2vKYbhlwar D5WIYT0lF6K4q3mdimeTRt/12sP5AD1T4l22iQm2NFDLOrCXhps7oucRNZg 9GlBIUX7/Onz02S
.facebook.com   TRUE    /   FALSE   1683492006  sb  YqSVYIj-CWidJrBuYpp3hwWF
.facebook.com   TRUE    /   FALSE   1683491692  datr    YqSVYMpaTnIQ053OKhPxted0
.atdmt.com  TRUE    /   FALSE   1683491693  ATN 1.1620419691.12398262919476711770.AYKqLQJgoNbrMvN37Rg
.facebook.com   TRUE    /   FALSE   1654361011  c_user  100007717814705
.google.com TRUE    /intl   FALSE   1685206659  _ga GA1.2-2.415491287.1622134656

but i need only string start with .facebook.com

exemple:

.facebook.com   TRUE    /   FALSE   1683492006  sb  YqSVYIj-CWidJrBuYpp3hwWF
.facebook.com   TRUE    /   FALSE   1683491692  datr    YqSVYMpaTnIQ053OKhPxted0
.facebook.com   TRUE    /   FALSE   1654361011  c_user  100007717814705

end all other delete.

input file cookie.txt -> output string with .facebook onlY!

how i can make this use JavaScript ?? ty

i try use .split and .replace ...

CodePudding user response:

try this..

var string; // your string here...
let lines = string.split("\n"),  // get each line
    FBstrings = []; // store facebook lines

for (const line of lines) {
    if (line && line.startsWith(".facebook.com")) FBstrings.push(line);
}

let stringWithFBOnly = FBstrings.join("\n");
  • Related