Skip to main content
added 8 characters in body
Source Link

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse it, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = / (.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('').trim();

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse it, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = /(.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('');

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse it, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = / (.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('').trim();

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

deleted 7 characters in body
Source Link

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse that shitit, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = /(.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('');

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse that shit, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = /(.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('');

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse it, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = /(.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('');

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);

console.log(x);
console.log(m);

Post Undeleted by I wrestled a bear once.
added 469 characters in body
Source Link

lol.. id din't meanYou don't need a loop, you can use the string's match method, but in order to post this yetget only the matched group you have to use a lookbehind, i wasn't done.which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse that shit, reverse all the matches and filter out empty strings to get the reservation codes. still editingSince you only have a single match for the names you don't need a loop for that either, disregardassuming there will always be a match, so you can just use exec and pop the result off the end..

const regex = /PREPARED FOR([^]*?)RESERVATION/;
    const regex2 = /AIRLINE RESERVATION CODE (.*)/;
    
    const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;
    let m;
var r1 = /(.*)(?= letEDOC x;NOITAVRESER ENILRIA)/g,
    
 r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const mrev = strs=>s.matchsplit(regex'').reverse().join('');
 
let x = consoler2.logexec(mstr).pop();
   let m = rev(str).searchmatch(regex2r1).map(rev).filter(w=>w.length);
     
console.matchlog(mx);
    console.log(m);

lol.. id din't mean to post this yet, i wasn't done.. still editing, disregard

const regex = /PREPARED FOR([^]*?)RESERVATION/;
    const regex2 = /AIRLINE RESERVATION CODE (.*)/;
    
    const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;
    let m;
    let x;
    
     m = str.match(regex);
    console.log(m);
    m = str.search(regex2);
    console.match(m);
    

You don't need a loop, you can use the string's match method, but in order to get only the matched group you have to use a lookbehind, which javascript's implementation of regex doesn't support, but, it does support a lookahead, so basically, you could reverse that shit, reverse all the matches and filter out empty strings to get the reservation codes. Since you only have a single match for the names you don't need a loop for that either, assuming there will always be a match, so you can just use exec and pop the result off the end..

const str = `30 OCT 2017  04 NOV 2017
    Distance (in Miles):500
    Stop(s): 0
    Distance (in Miles):500
    Stop(s):0
    TRIP TO KRAKOW, POLAND
    PREPARED FOR
    DOE/JANE MRS 
    APPLESEED/JOHN MR 
    RESERVATION CODE   UVWXYZ
    AIRLINE RESERVATION CODE DING67 (OS)
    AIRLINE RESERVATION CODE HDY75S (OS)`;

var r1 = /(.*)(?= EDOC NOITAVRESER ENILRIA)/g,
    r2 = /PREPARED FOR([^]*?)RESERVATION/g;

const rev = s=>s.split('').reverse().join('');

let x = r2.exec(str).pop();
let m = rev(str).match(r1).map(rev).filter(w=>w.length);
 
console.log(x);
console.log(m);

Post Deleted by I wrestled a bear once.
Source Link
Loading