Meaningless Drivel is fun!*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Angle brackets in Powershell" Watch "Angle brackets in Powershell" New topic
Author

Angle brackets in Powershell

Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 171
    
    5

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 matches...like 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?

Thanks!


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

Joined: Jul 21, 2011
Posts: 171
    
    5

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
Bartender

Joined: Apr 06, 2010
Posts: 4369
    
    8

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: http://aspose.com/file-tools
 
subject: Angle brackets in Powershell