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

195
Views
RegEx how to match everything exclude a string in a function

How can I exclude a string from the match in regex?

Input:

functionXY("Hello World"); 

Match:

functionXY();

i got this far with my regex expression:

/functionXY[(][)][;]/gm

but can't find the correct expression to exclude the string "Hello World" in the match.

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

0

You can use a regex to match everything inside the brackets, then use replace.

const str = 'functionXY("Hello World");';

const regex = /(?<=functionXY[(]).+(?=[)][;])/gm;

const res = str.replace(regex, '')
console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

Your pattern functionXY[(][)][;] uses square brackets for single characters and only matches functionXY();

Instead you can use 2 capture groups to capture what you want to keep, and match the double quotes and all chars other than double quotes that you don't want to keep.

In the replacement use 2 capture groups $1$2

(functionXY\()"[^"]*"(\);)

Regex demo

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!