nkg has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,

i need to match "}\n}" (without quotes and newline as in real).description of matching characters is below. How can I do it?

}

}

Replies are listed 'Best First'.
Re: How can I match this }\n} in perl
by hippo (Archbishop) on Feb 20, 2019 at 10:23 UTC

    One approach (of many):

    use strict; use warnings; use Test::More tests => 1; my $have = "foo}\n}"; my $re = qr/}\n}/; like $have, $re, 'Matched';

    Update: reduced the regex to make it even simpler.

Re: How can I match this }\n} in perl
by haukex (Archbishop) on Feb 21, 2019 at 08:15 UTC
    i need to match "}\n}" (without quotes and newline as in real).

    The regex to match "}\n}" is /}\n}/ (unless you're using m{}, in which case you need to write m{\}\n\}}). Since that's pretty obvious, I wonder if maybe you're having problems with some of your code? If that's the case, maybe you could show the code you're having problems with in the form of a Short, Self-Contained, Correct Example: a short, runnable piece of code that reproduces the issue, short sample input, the expected output for that input, and the output you're getting instead, including any error messages (code and input/output in <code> tags).

Re: How can I match this }\n} in perl
by chenhonkhonk (Acolyte) on Feb 22, 2019 at 18:54 UTC

    Without more information, that regex would work. Is it perhaps there's whitespace you're not accounting for, since it looks like you're searching for braces that end a block?

    If that's the case, I think you would want /}\n\w*}/ There's also a possibility you're editing a document from another filesystem, and newline is defaulting to your system. /}\n\r?}/ catches both Linux-y/Windows line endings.

      whitespace you're not accounting for ... If that's the case, I think you would want /}\n\w*}/

      That should probably be /}\n\s*}/, since \w means a word character.

      /}\n\r?}/

      That should probably be /}\r?\n}/, since \n\r would be LFCR (see also).

        Thanks. I don't use regex too often anymore but I mostly remember it!