Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:08:10+00:00 2026-05-26T04:08:10+00:00

In string n+n(n+n) , where n stands for any number or digit, I’d like

  • 0

In string n+n(n+n), where n stands for any number or digit, I’d like to match ( and replace it by *(, but only if it is followed by a number or digit.

Examples:

  • I’d like to change 2+22(2+2) into 2+22*(2+2),
  • I’d like to change -1(3) into -1*(3),
  • 4+(5/6) should stay as it is.

This is what I have:

var str = '2+2(2+2)'.replace(/^[0-9]\(/g, '*(');

But it doesn’t work. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:08:11+00:00Added an answer on May 26, 2026 at 4:08 am

    Remove the ^, and group the digits:

    '2+2(2+2)'.replace(/([0-9])\(/g, '$1*(')
    '2+2(2+2)'.replace(/(\d)\(/g, '$1*(')    //Another option: [0-9] = \d
    

    Suggestion: 2. is often a valid number (= 2). The following RegExp removes a dot between a number and a parenthesis.

    '2+2(2+2)'.replace(/(\d\).?\(/g, '$1*(') //2.(2+2) = 2*(2+2)
    

    Parentheses create a group, which can be referenced using $n, where n is the index of the group: $1.

    You started your RegExp with a ^..., which means: Match a part of the string which starts with .... This behaviour was certainly not intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String str = abcde123_92qwq_1a_02x_1e; I want to replace the first string part between the
string abc = 07:00 - 19:00 x = int.Parse(only first two characters) // should
I have the following string: Perl is the only language that looks the same
Is there any Java open source library that supports multi-character (i.e., String with length
I would like to create a Powershell script that automates parsing an XML, but
I've used strpbrk() occasionally while doing low-level string work in C, but I've never
I want to find any pattern matching: ###-##-#### and replace the ###-##, with ***-**
I have a regex to replace a certain pattern with a certain string, where
I'm receiving a formatted date string like this via the pivotal tracker API: 2012/06/05
Possible Duplicate: PHP - Need to remove duplicate characters within a String but would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.