Quantcast
Channel: Forcing Bash to use Perl RegEx Engine - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by slm for Forcing Bash to use Perl RegEx Engine

$
0
0

Bash doesn't support a method for you to do this at this time. You're left with the following options:

  1. Use Perl
  2. Use grep [-P|--perl-regexp]
  3. Use Bash functionality to code it

I think I would go with #2 and try and use grep to get what I want functionally. For back referencing you can do the following with grep:

$ echo 'BEGIN `helloworld` END' | grep -oP '(?<=BEGIN `).*(?=` END)'
helloworld

-o, --only-matching       show only the part of a line matching PATTERN
-P, --perl-regexp         PATTERN is a Perl regular expression

(?=pattern)
    is a positive look-ahead assertion
(?!pattern)
    is a negative look-ahead assertion
(?<=pattern)
    is a positive look-behind assertion
(?<!pattern)
    is a negative look-behind assertion 

References


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>