I have trouble spliting my regex in multiple line. I want my regex to match the line given:
* Code \"l;k\"\"dfsakd;.*[])_lkaDald\"
So I created
What the x
flag does is very simply say 'ignore whitespace'.
So you no longer match 'space' characters , and instead have to use
\s
or similar.
So you can write:
if ( m/
^
\d+\s+
fish:\w+\s+
$
/x ) {
print "Matched\n";
}
You can test regular expressions with various websites but one example is https://regex101.com/
So to take your example: https://regex101.com/r/eG5jY8/1
But how is yours not working?
This matches:
my $string = q{* Code "l;k""dfsakd;.*[])_lkaDald"};
my $firstRegexpr = qr/^\s*
\*
\s*
Code\s+
\"
(?<Code>((\")*[^\"]+)+)
\"
/x;
print "Compiled_Regex: $firstRegexpr\n";
print "Matched\n" if ( $string =~ m/$firstRegexpr/ );
And as for not having $]
- there's two answers. Either: Use \
to escape it, or use \Q\E
.