Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for any string not ending on .js

Tags:

People also ask

What is ?! In regex?

The ?! n quantifier matches any string that is not followed by a specific string n.

Does regex work in JavaScript?

In JavaScript, you can write RegExp patterns using simple patterns, special characters, and flags. In this section, we'll explore the different ways to write regular expressions while focusing on simple patterns, special characters, and flags.

How do I escape a character in regex?

The \ is known as the escape code, which restore the original literal meaning of the following character. Similarly, * , + , ? (occurrence indicators), ^ , $ (position anchors) have special meaning in regex. You need to use an escape code to match with these characters.

How do you check if a regex is valid in JS?

JavaScript RegExp test() The test() method tests for a match in a string. If it finds a match, it returns true, otherwise it returns false.


This has been driving me nuts. I'm trying to match everything that doesn't end in .js. I'm using perl, so ?<! etc. is more than welcome.

What I'm trying to do:

Do match these

mainfile
jquery.1.1.11
my.module

Do NOT match these

mainfile.js
jquery.1.1.11.js
my.module.js

This should be an insanely simple task, but I'm just stuck. I looked in the docs for both regex, sed, perl and was even fiddling around for half an hour on regexr. Intuitively, this example (/^.*?(?!\.js)$/) should do it. I guess I just stared myself blind.

Thanks in advance.