Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex/linux find command not working as expected

Tags:

regex

find

bash

Background: I'm trying to get a total line count of all of the code files (.html|.htm|.php|.js|.css) in my root web dir (recursively) by piping the output of this into xargs wc -l | grep total.

$ find . -regex '.+\.php'
./inc/db.php
./inc/userauth.php
./index.php
.......... etc.

$ find . -regex '.+\.js'
./inc/jquery-1.7.1.js
./inc/script.js

$ find . -regex '.+\.(php|js)'
(returns nothing)

According to this,

abc(def|xyz) matches abcdef or abcxyz

So shouldn't .+\.(php|js) match all .php files and .js files?

like image 492
Andrew Rasmussen Avatar asked Dec 27 '22 05:12

Andrew Rasmussen


1 Answers

find uses a different style of regex, so you have to write \(js\|php\) instead of just (js|php).

like image 101
Tikhon Jelvis Avatar answered Jan 10 '23 22:01

Tikhon Jelvis