Perl reads, by default, lines using the newline as the delimiter
You can not match what it is not there.
To read multiple lines chucks, you can change the default $/=""; for grabbing paragraphs $/= undef; for grabbing the whole file
After that you need to modify how matches occur, by letting it know that you want to use the (.) to match newline as well and that you are using multiline mode so the `^' and `$' do not get in the way.
You do that with the modifiers `m' and `s'
Some more info
hi,
i got a problem with understanding regular expressions. what i wanna do is
scanning the wtmp logfile for ips and if a specific ip is echoed id like to be a part of a text to be assigned to it.
the scanning is done with
#! /bin/bash
cat wtmp | strings | egrep -o "+\.+\.+\." | sort -u... (6 Replies)
I have the following code:
#!/usr/bin/perl -w
@files = <*.csv>;
foreach $file (@files) {
open(FH, $file) || die("Error: Cannot open file $file for reading.");
my @dt = ($file =~ /^(\w+).(\d{6})\.csv$/);
while (<FH>) {
print "@dt $_\n";
}
close(FH);
}
There is redundancy... (10 Replies)
Hi
I have a question on regex
There is a line in a script like
my_file="$(echo SunMonTueWed | sed "s//_&g") "
My question what does the expression _&g do.
Obviously in this example the output is
_Sun_Mon_Tue_Wed
Another question can i use some trick to get the result like... (3 Replies)
Hi, im sure this is really simple but i cant quite figure it out. how do i test against a word at the beginning of the line but up to the point of a delimiter i.e. ":"
for example if i wanted to test against the user in the /etc/passwd file
peter:x:101:100:peters account:/var/peter:/bin/sh
... (3 Replies)
$var=~ s#(\n?<a>.*?</a>\n)##s
$pat=$1
Recently i came across this bit of a code.
Can someone please explain the function of these two line? (5 Replies)
Hello all
Is there a "not" reversal method for the =~ regex thingy in perl ?
for example, in the snippet below, i have placed a ! in front of the =~ to "not it".. although it quite obviously doesn't work and is just me trying to get across the question in a way that somebody may understand :o... (2 Replies)
I have a basic question regarding * and . while using regex:
# echo 3 | grep ^*$
3
I think I understood why it outputs "3" here (because '*' matches zero or more of the previous character) but I don't understand the output of the following command:
# echo 3 | grep ^.$
#
I thought I... (7 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hi I am trying to match lines having following string
BIND dn="uid=
putting something like this is not working :
/\sBIND dn="uid=/
Any suggestion.
Thanks. John (9 Replies)
I am not a big expert in regex and have just little understanding of that language.
Could you help me to understand the regular Perl expression:
^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{
------
This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies
LEARN ABOUT REDHAT
re
re(3pm) Perl Programmers Reference Guide re(3pm)NAME
re - Perl pragma to alter regular expression behaviour
SYNOPSIS
use re 'taint';
($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
$pat = '(?{ $foo = 1 })';
use re 'eval';
/foo${pat}bar/; # won't fail (when not under -T switch)
{
no re 'taint'; # the default
($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
no re 'eval'; # the default
/foo${pat}bar/; # disallowed (with or without -T switch)
}
use re 'debug'; # NOT lexically scoped (as others are)
/^(.*)$/s; # output debugging info during
# compile and run time
use re 'debugcolor'; # same as 'debug', but with colored output
...
(We use $^X in these examples because it's tainted by default.)
DESCRIPTION
When "use re 'taint'" is in effect, and a tainted string is the target of a regex, the regex memories (or values returned by the m// opera-
tor in list context) are tainted. This feature is useful when regex operations on tainted data aren't meant to extract safe substrings,
but to perform other transformations.
When "use re 'eval'" is in effect, a regex is allowed to contain "(?{ ... })" zero-width assertions even if regular expression contains
variable interpolation. That is normally disallowed, since it is a potential security risk. Note that this pragma is ignored when the
regular expression is obtained from tainted data, i.e. evaluation is always disallowed with tainted regular expresssions. See "(?{ code
})" in perlre.
For the purpose of this pragma, interpolation of precompiled regular expressions (i.e., the result of "qr//") is not considered variable
interpolation. Thus:
/foo${pat}bar/
is allowed if $pat is a precompiled regular expression, even if $pat contains "(?{ ... })" assertions.
When "use re 'debug'" is in effect, perl emits debugging messages when compiling and using regular expressions. The output is the same as
that obtained by running a "-DDEBUGGING"-enabled perl interpreter with the -Dr switch. It may be quite voluminous depending on the complex-
ity of the match. Using "debugcolor" instead of "debug" enables a form of output that can be used to get a colorful display on terminals
that understand termcap color sequences. Set $ENV{PERL_RE_TC} to a comma-separated list of "termcap" properties to use for highlighting
strings on/off, pre-point part on/off. See "Debugging regular expressions" in perldebug for additional info.
The directive "use re 'debug'" is not lexically scoped, as the other directives are. It has both compile-time and run-time effects.
See "Pragmatic Modules" in perlmodlib.
perl v5.8.0 2002-06-01 re(3pm)