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

206
Views
regexp to get words up next, exists or not

This regexp is matching strings after /ab. Also, i would like to match empty strings after /ab. How can i do that?. Thanks in advance.

const TelegramBot = require('node-telegram-bot-api');
const token = process.env.TOKEN;
const bot = new TelegramBot(token, { polling: true });

bot.onText(/\/ab (.+)/, (msg, match) => {
    const chatId = msg.chat.id
    const prompt = match[1]
    bot.sendMessage(chatId, prompt)
})

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

0

Use a lookbehind: /^(?![\s\S])|(?<=\/ab).*/g

A lookbehind (?<=) will match anything in front of it without being included in the actual match. As for return an empty string, you'll need to explicitly return a "" if there's no match. You can change this line maybe: Added an alternate ^(?!\[\s\S\])|

const rgx = new RegExp(/^(?![\s\S])|(?<=\/ab).*/, 'g');

const str = `/ab 1234 hdsso
/abksdfsioiowe
/ab
khbigigi7 
s366s7d /ab`;

let matches = [...str.matchAll(rgx)].flat();

console.log(matches);

Regex101

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!