Search code examples
regexperlpcre

Multiple names for the same perl named regex extraction


I'm working a regex written by someone else. I need to have an existing named extraction aliased to use a different name.

Basically the chunk of the regex I'm working with looks like this:

(-|(?<objectname>.*\\(?<process>[^\r\n\\]+))

This matches up to a part of a log, containing a path to an executable.

Which pulls out the content that I need into objectname, and the executable name minus the path into process.

I need to alias objectname to also be returned if I look for objectID. I'm not looking for the /j operator for multiple groups with the same name.


Solution

  • Just wrap the named capture in another named capture group:

    (-|(?<objectID>(?<objectname>.*\\(?<process>[^\r\n\\]+)))