-2
 $str = "doctor_who:eeh1234LMNOP51234.123";

I want to match doctor_who:ee not doctor_who:eeh;

 $str =~ m/doctor_who:e(?!eh)[epx];

I want to know the role of regular expression within Parentheses;

tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
  • Please learn to format your posts properly. You should read [*Markdown Editing Help*](http://stackoverflow.com/editing-help) – Borodin Jul 27 '16 at 01:33
  • 1
    `$str =~ m/doctor_who:e(?!eh)[epx];` won't compile. Please *copy and paste* your **real code** into any questions – Borodin Jul 27 '16 at 01:35
  • `(?!PAT)` means "is not followed by `PAT`", or more precisely, "`PAT` does not match at this position". – ikegami Jul 27 '16 at 02:57

1 Answers1

3

A component like (?! ... ) will fail to match if the following characters in the target string match the enclosed regex pattern. It's called a negative look-ahead

It's unclear whether you need help to form a pattern to your requirements, or if you've come across a pattern that you don't understand

If I was writing it, I'd look at your specification

I want to match 'doctor_who:ee' not 'doctor_who:eeh'

You want to match doctor_who:ee that isn't followed by h, which is

/doctor_who:ee(?!h)/
Borodin
  • 126,100
  • 9
  • 70
  • 144