• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Angle brackets in Powershell

 
Tina Smith
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Tina Smith
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic