New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: regexp flag to not set $1, $2 etc. #9451
Comments
From @epaCreated by @epaWhen a regexp has capturing parentheses it sets match variables from <http://rt.cpan.org/Ticket/Display.html?id=36956> In most situations you can avoid the problem by following two rules: It would simplify these situations to have a flag meaning do not my $str = 'hello'; would set $x to 'h' and $y to 'e' as now, but would not touch the old In module code where you have to be cautious about trampling on other Perl Info
|
From @AbigailOn Mon, Aug 18, 2008 at 09:00:06AM -0700, Ed Avis wrote:
You can already do this easily currently: "foo" =~ /(\w)(\w)/; Abigail |
The RT System itself - Status changed from 'new' to 'open' |
From norbi@nix.huOn Tue Aug 19 00:34:49 2008, abigail@abigail.be wrote:
Yeah, that's exactly the method I chose for fixing NEXT |
1 similar comment
From norbi@nix.huOn Tue Aug 19 00:34:49 2008, abigail@abigail.be wrote:
Yeah, that's exactly the method I chose for fixing NEXT |
From @cpansproutOn Tue Aug 19 00:34:49 2008, abigail@abigail.be wrote:
We should optimise do {$str =~ /(...)/} not to bother with the pre-match Likewise, do {$str =~ s/(...)//} should consider in-place substitution, -- Father Chrysostomos |
From @epaI think this bug can be closed because of the suggested alternative of do { $str =~ /regexp/ }; |
@iabyn - Status changed from 'open' to 'rejected' |
From @xsawyerxOn Fri, 09 Jun 2017 08:31:11 -0700, ed wrote:
There is also /n: n Prevent the grouping metacharacters "()" from capturing. This "hello" =~ /(hi|hello)/; # $1 is "hello" This is equivalent to putting "?:" at the beginning of every capturing "hello" =~ /(?:hi|hello)/; # $1 is undef "/n" can be negated on a per-group basis. Alternatively, named "hello" =~ /(?-n:(hi|hello))/n; # $1 is "hello" |
From @epaThere is some discussion in bug 127617 about why the /n modifier is not always usable. However, the technique do { /(a)\1/ } do { /(a)(?1)/ } stops $1 being set externally, but doesn't break the backreference \1 or the recursive subpattern (?1). |
From @khwilliamsonOn Sun, 11 Jun 2017 03:24:19 -0700, ed wrote:
Would you care to submit a patch documenting this technique? |
From @cpansproutOn Sun, 11 Jun 2017 07:03:11 -0700, khw wrote:
I might suggest ‘more versatile, but slower’ rather than ‘better’. Whether it is better depends on your use case. -- Father Chrysostomos |
Migrated from rt.perl.org#58072 (status was 'rejected')
Searchable as RT58072$
The text was updated successfully, but these errors were encountered: