Sponsored Content
Full Discussion: Regular expressions - Perl
Top Forums Shell Programming and Scripting Regular expressions - Perl Post 302251561 by otheus on Monday 27th of October 2008 12:26:55 PM
Old 10-27-2008
The problem is probably the $. That means end-of-line, but login didn't produce an end of line. Try /\blogin:/.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl regular expressions...

I am writing script that will act like the 'comm' utility. My problem is when trying to read whether the user has entered -123 or -1 or -1...etc. I currently have: if(m/??/g){ print "Good.\n"; } So, this should check for all... (1 Reply)
Discussion started by: DrRo183
1 Replies

2. UNIX for Dummies Questions & Answers

regular expressions

how to find for a file whose name has all characters in uppercase after 'project'? I tried this: find . -name 'project**.pdf' ./projectABC.pdf ./projectABC123.pdf I want only ./projectABC.pdf What is the regular expression that correponds to "all characters are capital"? thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies

3. UNIX for Dummies Questions & Answers

Regular Expressions HELP - PERL

Hello, $line=USING (FILE '/TEST1/FILENAME'5000) I want to reterive the value between ' and ) which is 5000 here. i have tried out the following expressions ... Type 1 : $Var1=`sed -e 's/.*\' //' -e 's\).*$/' $line`; Type 2 : $Var1=`echo $line | awk -F"\'" '{print $2}' | awk -F"\\)"... (1 Reply)
Discussion started by: maxmave
1 Replies

4. Shell Programming and Scripting

Regular Expressions HELP - PERL

Hello, $line=USING (FILE '/TEST1/FILENAME'5000) I want to reterive the value between ' and ) which is 5000 here. i have tried out the following expressions ... Type 1 : $Var1=`sed -e 's/.*\' //' -e 's\).*$/' $line`; Type 2 : $Var1=`echo $line | awk -F"\'" '{print $2}' | awk -F"\\)"... (3 Replies)
Discussion started by: maxmave
3 Replies

5. Shell Programming and Scripting

perl regular expressions and field search

Hello guys/gals, i am sorry as this is probably very simply but i am slowly learning perl and need to convert some old korn shell scripts. I need to be able to search a file line by line but only match a string at particular location on that line, for example character 20-30. So my file... (4 Replies)
Discussion started by: dynamox
4 Replies

6. Shell Programming and Scripting

regular expressions using perl script

i have a set of regular expressions. The words in the regular expression should be used to replace the i/p with hyphens '---'. i need perl script to evaluate these regular expression. the words in the regexes when found in the i/p file should be replaced with hyphens '---'. the set of regular... (3 Replies)
Discussion started by: Sgiri1
3 Replies

7. Shell Programming and Scripting

Perl regular expressions don't like the @ ("at") sign.

Take a look at this code: #!/usr/bin/perl use 5.008; $_ = "somename@address.com"; if(/\@\w+\.com/) { print "\n\nmight be an email address\n\n"; } else { print "\n\nnot an email address\n\n"; } Shouldn't the /\@\w+\.com/ evaluate as true? I've also tried: ... (3 Replies)
Discussion started by: mrwatkin
3 Replies

8. Programming

Which language is best suited for regular expressions perl,python.ruby ?

Hello all, i am in a bit of dilema here. i dont know any thing about perl or python. only know a little bit of awk. now unable to take a decission as to which language to go for. my requirement is building a testing framework.suite which will execute ssytem comands remotely on unix... (2 Replies)
Discussion started by: achak01
2 Replies

9. Shell Programming and Scripting

Perl - Regular Expressions - Match complete word only

Hi Team, I have two strings like: xxx|yyy|Arizona Cardinals| Tell Cardinals | Cardinals bbb|Bell Earn, Jr | Bell Earn | Jayhawks | hawks I have a lookup file which has a set of strings. These need to be removed from above two strings Lookup file Contents: Bell Earn, Jr hawks... (2 Replies)
Discussion started by: forums123456
2 Replies

10. Shell Programming and Scripting

PERL Regular Expressions

im trying to extract some tags between and in a file..for eg..the file format is I want the and extracted from the file i.e the tags which is present b/w and I have the regex for extracting the tags from the whole file but how to specify my search within the and... (1 Reply)
Discussion started by: rajkrishna89
1 Replies
Regexp::Optimizer(3pm)					User Contributed Perl Documentation				    Regexp::Optimizer(3pm)

NAME
Regexp::Optimizer - optimizes regular expressions SYNOPSIS
use Regexp::Optimizer; my $o = Regexp::Optimizer->new; my $re = $o->optimize(qr/foobar|fooxar|foozap/); # $re is now qr/foo(?:[bx]ar|zap)/ ABSTRACT
This module does, ahem, attempts to, optimize regular expressions. INSTALLATION
To install this module type the following: perl Makefile.PL make make test make install DESCRIPTION
Here is a quote from perltodo. Factoring out common suffices/prefices in regexps (trie optimization) Currently, the user has to optimize "foo|far" and "foo|goo" into "f(?:oo|ar)" and "[fg]oo" by hand; this could be done automatically. This module implements just that. EXPORT Since this is an OO module there is no symbol exported. METHODS
This module is implemented as a subclass of Regexp::List. For methods not listed here, see Regexp::List. $o = Regexp::Optimizer->new; $o->set(key => value, ...) Just the same us Regexp::List except for the attribute below; unexpand When set to one, $o->optimize() tries to $o->expand before actually starting the operation. # cases you need to set expand => 1 $o->set(expand => 1)->optimize(qr/ foobar| fooxar| foozar /x); $re = $o->optimize(regexp); Does the job. Note that unlike "->list2re()" in Regexp::List, the argument is the regular expression itself. What it basically does is to find groups will alterations and replace it with the result of "$o->list2re". $re = $o->list2re(list of words ...) Same as "list2re()" in Regexp::List in terms of functionality but how it tokenize "atoms" is different since the arguments can be regular expressions, not just strings. Here is a brief example. my @expr = qw/foobar fooba+/; Regexp::List->new->list2re(@expr) eq qr/fooba[+r]/; Regexp::Optimizer->new->list2re(@expr) eq qr/foob(?:a+ar)/; CAVEATS
This module is still experimental. Do not assume that the result is the same as the unoptimized version. o When you just want a regular expression which matches normal words with not metacharacters, use <Regexp::List>. It's more robus and much faster. o When you have a list of regular expessions which you want to aggregate, use "list2re" of THIS MODULE. o Use "->optimize()" when and only when you already have a big regular expression with alterations therein. "->optimize()" does support nested groups but its parser is not tested very well. BUGS
o Regex parser in this module (which itself is implemented by regular expression) is not as thoroughly tested as Regexp::List o May still fall into deep recursion when you attempt to optimize deeply nested regexp. See "PRACTICALITY". o Does not grok (?{expression}) and (?(cond)yes|no) constructs yet o You need to escape characters in character classes. $o->optimize(qr/[a-z()]|[A-Z]/); # wrong $o->optimize(qr/[a-z()]|[A-Z]/); # right $o->optimize(qr/[0-9A-Za-z]|[Q-_.!~*"'()E]/ # right, too. o When character(?: class(?:es)?)? are aggregated, duplicate ranges are left as is. Though functionally OK, it is cosmetically ugly. $o->optimize(qr/[0-5]|[5-9]|0123456789/); # simply turns into [0-5][5-9]0123456789] not [0-9] I left it that way because marking-rearranging approach can result a humongous result when unicode characters are concerned (and p{Properties}). PRACTICALITY
Though this module is still experimental, It is still good enough even for such deeply nested regexes as the followng. # See 3.2.2 of http://www.ietf.org/rfc/rfc2616.txt # BNF faithfully turned into a regex http://(?:(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|(?:(?:[a-z]|[A-Z])|[0-9])(?:(?:(?:[a-z]|[A-Z])|[0-9])|-)*(?:(?:[a-z]|[A-Z])|[0-9])).)*(?:(?:[a-z]|[A-Z])|(?:[a-z]|[A-Z])(?:(?:(?:[a-z]|[A-Z])|[0-9])|-)*(?:(?:[a-z]|[A-Z])|[0-9])).?|[0-9]+.[0-9]+.[0-9]+.[0-9]+)(?::[0-9]*)?(?:/(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*(?:;(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*)*(?:/(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*(?:;(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*)*)*(?:\?(?:[;/?:@&=+$,]|(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f]))*)?)? # and optimized http://(?::?[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.[a-zA-Z]*(?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.?|[0-9]+.[0-9]+.[0-9]+.[0-9]+)(?::[0-9]*)?(?:/(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*(?:;(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*)*(?:/(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*(?:;(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*)*)*(?:\?(?:(?:[;/?:@&=+$,a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f]))*)?)? By carefully examine both you can find that character classes are properly aggregated. SEE ALSO
Regexp::List -- upon which this module is based "eg/" directory in this package contains example scripts. Perl standard documents L<perltodo>, L<perlre> CPAN Modules Regexp::Presuf, Text::Trie Books Mastering Regular Expressions <http://www.oreilly.com/catalog/regex2/> AUTHOR
Dan Kogai <dankogai@dan.co.jp> COPYRIGHT AND LICENSE
Copyright 2003 by Dan Kogai This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2004-12-05 Regexp::Optimizer(3pm)
All times are GMT -4. The time now is 09:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy