-1

I need to retrieve the field user from this spool file

(********* TOP SEPARATOR ***************************************\
*****************) 48 Tj
0 -1.1 Td
(*        REPORT = COURR QRCODE MOB                             \
 USER = BINM3   *) 48 Tj
0 -2.2 Td
(*        DESC.  = COURRIER E-CLIENT QR CODE MOBILE             \
 FORM = 72A2    *) 48 Tj
0 -3.3 Td
(*        CAPTURE DATE  = 15/05/19 \(19.135\)   TIME = 14.30.45 \
       \(VTUB001 \) *) 48 Tj
0 -4.4 Td
(************************************                           \

TEST
FILE
TEST
FILE

(********* END SEPARATOR ***************************************\
*****************) 48 Tj
0 -1.1 Td
(*        REPORT = COURR QRCODE MOB                             \
 USER = BINM3   *) 48 Tj
0 -2.2 Td
(*        DESC.  = COURRIER E-CLIENT QR CODE MOBILE             \
 FORM = 72A2    *) 48 Tj
0 -3.3 Td
(*        CAPTURE DATE  = 15/05/19 \(19.135\)   TIME = 14.30.45 \
       \(VTUB001 \) *) 48 Tj
0 -4.4 Td
(************************************     

                  \

I use this

(?<=USER = ).*?(?=\s)

But i have 2 result and i need only one, the first

How do I solve this problem?

Emma
  • 27,428
  • 11
  • 44
  • 69
Bilna0
  • 1
  • 2

1 Answers1

0

This expression may not be the fastest one, however it returns your desired output, in the second capturing group:

(.*)USER = ([^\s]+)([\s\S]*)

If you want, you can add more boundaries to it, such as list of chars instead of ([^\s]+) or maybe, start and end chars:

^(.*)USER = ([^\s]+)([\s\S]*)$

enter image description here

Demo

JavaScript Demo

const regex = /(.*)USER = ([^\s]+)([\s\S]*)/gm;
const str = `(********* TOP SEPARATOR ***************************************\\ *****************) 48 Tj 0 -1.1 Td (* REPORT = COURR QRCODE MOB \\ USER = BINM3 ) 48 Tj 0 -2.2 Td ( DESC. = COURRIER E-CLIENT QR CODE MOBILE \\ FORM = 72A2 ) 48 Tj 0 -3.3 Td ( CAPTURE DATE = 15/05/19 (19.135) TIME = 14.30.45 \\ (VTUB001 ) *) 48 Tj 0 -4.4 Td (************************************ \\

TEST FILE TEST FILE

(********* END SEPARATOR ***************************************\\ *****************) 48 Tj 0 -1.1 Td (* REPORT = COURR QRCODE MOB \\ USER = BINM3 ) 48 Tj 0 -2.2 Td ( DESC. = COURRIER E-CLIENT QR CODE MOBILE \\ FORM = 72A2 ) 48 Tj 0 -3.3 Td ( CAPTURE DATE = 15/05/19 (19.135) TIME = 14.30.45 \\ (VTUB001 ) *) 48 Tj 0 -4.4 Td (************************************ \\`;
const subst = `$2`;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log('Substitution result: ', result);

RegEx Circuit

You can also visualize your expressions in jex.im:

enter image description here

Community
  • 1
  • 1
Emma
  • 27,428
  • 11
  • 44
  • 69