Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Regular expression to stop at specific character, return null if doesn't match

I have this string:

|AL;GF=0;ID=17;AF=122|CT;GF=0;ID=15;AF=123|BD;GF=0;ID=1;AF=124|

I want to match if CT block (have CT; between |) has ID=1, i tried:

/\|CT;.*?ID=1;(?=.*\|)/

But doesn't working.

Code:

let string = '|AL;GF=0;ID=17;AF=122|CT;GF=0;ID=15;AF=123|BD;GF=0;ID=1;AF=124|'
console.log(string.match(/\|CT;.*?ID=1;(?=.*\|)/g))

// return ['|CT;GF=0;ID=15;AF=123|BD;GF=0;ID=1;']
// expected null

Someone can help me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use

/\|CT;[^|]*ID=1;/

See the regex demo.

Details:

  • \|CT; - |CT; string
  • [^|]* - zero or more chars other than a | char
  • ID=1; - a fixed string.

See a JavaScript demo:

const strings = [
  '|AL;GF=0;ID=17;AF=122|CT;GF=0;ID=15;AF=123|BD;GF=0;ID=1;AF=124|',
  '|AL;GF=0;ID=17;AF=122|CT;GF=0;ID=1;AF=123|BD;GF=0;ID=1;AF=124|'
]
for (const string of strings) {
    console.log(string.match(/\|CT;[^|]*ID=1;/)?.[0]);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!