Two Laptop Bag
The moose likes Other Languages and the fly likes Angle brackets in Powershell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Angle brackets in Powershell" Watch "Angle brackets in Powershell" New topic

Angle brackets in Powershell

Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 208

Hi all,
So I have a powershell script that I need to rewrite as a linux shell script, but I don't understand part of the regular expressions that are used. The regex looks like this:

My question is what does ?<indent> mean? (for Google's sake, this is a question mark followed by angle brackets containing what I think is an identifier) It seems to be treated as an index into the regex so:

But I haven't been able to find any documentation on my friend Google explaining how this works, and whether it is a powershell specific feature or something that can be adapted to regular expressions in general. Does anyone know of a good resource for powershell that covers this information or can explain it here?


Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 208

After a little more looking, it seems that what I was thinking is right: the groups inside an individual regex can be named in powershell. As opposed to counting those groups with numbers.
Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

Yes, that's called a "named capturing group". I don't know much about PowerShell, but other languages do have them. They were added to Java, for instance, in Java 7 - see java.util.regex.Pattern (look for "Special constructs") and java.util.regex.Matcher#group(java.lang.String).
I agree. Here's the link:
subject: Angle brackets in Powershell
It's not a secret anymore!