Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I have a regex created by myself that I am currently running in PHP. Although when I merge it over to Javascript, it refuses to work. I have also tried it in Python and it works perfectly fine.

Regex:

@[[](.[^]]+)[]][()](\d+)[)]

Testing in PHP, and working

Testing in Javascript, and not working

share|improve this question
2  
have a look at the explanation - see how it differs, regex's are slightly different in different languages - make adjustments as required –  Jaromanda X 5 hours ago

1 Answer 1

JavaScript doesn't automatically escape your ].

This will help you get a visual idea:

PCRE:

PCRE

JS:

JS

Python:

Python

So to fix this, you need to escape the brackets

@[[](.[^\]]+)[\]][()](\d+)[)]
//      ^     ^  

That's why it's good practice to escape this stuff instead of relying on quirks of the flavor.

I generated these images through regex101.

share|improve this answer
    
Ohhhh, makes much more sense now. Thanks vihan, appreciate it. –  Fizzix 5 hours ago
    
Sweet. Great answer! –  Darragh 5 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.