Skip to content Skip to sidebar Skip to footer

Convert Javascript Regexp To Work With Grep Or Sed

I needed to grep some files on a server so I quickly hacked out and tested a regexp in a javascript console to meet my needs: var regexp = /mssql_query\s*\([\'\'][a-z0-9_\s]*(_sp|u

Solution 1:

grep "mssql_query *([\"\'][a-z0-9_ ]*_sp\|usp_"

ought to do the job. It is looking for:

  1. mssql_query, then
  2. 0 or more spaces (that's the " *"), then
  3. (, then " or ' (that's the ([\"\']), then
  4. 0 or more characters that are lowercase letters, numbers, underscores or spaces (that's the [a-z0-9_ ]*), then
  5. _sp or usp_ (that's the _sp\|usp_)

Solution 2:

use egrep (alias for grep -E , using extended regular expressions).

also instead of the /i modifier use the -i flag for grep.

Post a Comment for "Convert Javascript Regexp To Work With Grep Or Sed"