0

I m trying to create a regex with a string of numbers and special characters in which, if there is a % then the number before and after the % will be replaced by "(" & ")".

Ex.

case 1:

var str = "1*2/9%";

will give me "1*2/(9%)"

case 2:

var str = "1*2/9%8%7";

will give me "1*2/((9%)8%)7"

Please help me with this regex. Thanks in advance.

kunal panchal
  • 798
  • 5
  • 21
  • 1
    Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/a/2759417/3832970) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Mar 06 '20 at 16:25
  • 1
    hey, @WiktorStribiżew thanks a lot for your suggestion. I will surely check the link and still if I face any issue I will edit the same. :) – kunal panchal Mar 07 '20 at 09:09
  • You may search for something like "javascript regex number" and "javascript regex wrap the match with tags" to get the links to SO questions that must solve your problem. Oh, just searched for the second phrase - https://stackoverflow.com/a/53857549/3832970 – Wiktor Stribiżew Mar 07 '20 at 10:27

0 Answers0