tags:

views:

80

answers:

1

Is it possible to do something like (?'A-B'\s*) ?

+2  A: 

From the docs:

(?<name1-name2>subexpression)

(Balancing group definition.) Deletes the definition of the previously defined group name2 and stores in group name1 the interval between the previously defined name2 group and the current group. If no group name2 is defined, the match backtracks. Because deleting the last definition of name2 reveals the previous definition of name2, this construct allows the stack of captures for group name2 to be used as a counter for keeping track of nested constructs such as parentheses. In this construct, name1 is optional. You can use single quotes instead of angle brackets; for example, (?'name1-name2').

Your example only works if there exists a group named B already defined in the regex, and you intend to do what A-B implies.

If you're asking if a group name can have a dash in it, no. The dash has a special meaning in named groups.

For more information, see the example in this topic.

Will