Re: multiple named captures with a single regexp

2017-03-01 Thread Chas. Owens
/(\w+)/g gets the command as well and only the args are wanted, so it would need to be my @args = $s =~ / (\w+)/g; shift @args; also, my VAR if TEST; is deprecated IIRC and slated to be removed soon (as it's behavior is surprising). It would probably be better to say my @args = $s =~ /^\w+\s/

Re: multiple named captures with a single regexp

2017-03-01 Thread X Dungeness
On Wed, Mar 1, 2017 at 2:52 AM, Chas. Owens wrote: > Sadly, Perl will only capture the last match of capture with a qualifier, so > that just won't work. The split function really is the simplest and most > elegant solution for this sort of problem (you have a string with a > delimiter and you wa

Re: multiple named captures with a single regexp

2017-03-01 Thread Chas. Owens
l doesn't handle Unix commands properly as you can escape " and use ' to create strings, but those details are left as an exercise for the reader. On Wed, Mar 1, 2017 at 4:04 AM Luca Ferrari wrote: > Hi all, > I'm not sure if this is possible, but imagine I've got a

Re: multiple named captures with a single regexp

2017-03-01 Thread Shlomi Fish
Hi Luca, On Wed, 1 Mar 2017 10:01:34 +0100 Luca Ferrari wrote: > Hi all, > I'm not sure if this is possible, but imagine I've got a line as follows: > > command arg1 arg2 arg3 arg4 ... > > I would like to capture all args with a single regexp, possibly with a >

multiple named captures with a single regexp

2017-03-01 Thread Luca Ferrari
Hi all, I'm not sure if this is possible, but imagine I've got a line as follows: command arg1 arg2 arg3 arg4 ... I would like to capture all args with a single regexp, possibly with a named capture, but I don't know exactly how to do: my $re = qr/command\s+(?\w+)+/; the abo

Re: Regexp under PERL

2015-07-08 Thread Kent Fredric
On 8 July 2015 at 19:12, Nagy Tamas (TVI-GmbH) wrote: > This is the code: > > } elsif (defined($row) && ($row =~ m/\(\*[ ]+\"\@PATH\"[ ]+:=[ > ]+'(\/)?([\*A-Za-z_ ]*(\/)?)+'[ ]\*\)?/)) { > # PATH first version: \(\*[ ]+@PATH[ ]+:=[ ]+'(\\/)?([\*A-Za-z_ > ]*(\\/)?)+'[ ]\*\)? > > my @

AW: Regexp under PERL

2015-07-08 Thread Nagy Tamas (TVI-GmbH)
ntfred...@gmail.com] Gesendet: Dienstag, 7. Juli 2015 19:03 An: Nagy Tamas (TVI-GmbH) Cc: beginners@perl.org Betreff: Re: Regexp under PERL On 8 July 2015 at 04:40, Nagy Tamas (TVI-GmbH) wrote: > m/\(\*[ ]+\"\@PATH\"[ ]+:=[ ]+'(\/)?([\*A-Za-z_ ]*(\/)?)+'[ ]\*\)?/)) This is

Re: Regexp under PERL

2015-07-07 Thread Kent Fredric
On 8 July 2015 at 04:40, Nagy Tamas (TVI-GmbH) wrote: > m/\(\*[ ]+\"\@PATH\"[ ]+:=[ ]+'(\/)?([\*A-Za-z_ ]*(\/)?)+'[ ]\*\)?/)) This is not the exact code you 're using obviously, because the last 2 ")" marks are actually outside the regex. Removing those ))'s makes the regex compile just fine. S

Regexp under PERL

2015-07-07 Thread Nagy Tamas (TVI-GmbH)
Hi, PERL shows this line ok, but for the next lines it tells: String found where operator expected at line... m/\(\*[ ]+\"\@PATH\"[ ]+:=[ ]+'(\/)?([\*A-Za-z_ ]*(\/)?)+'[ ]\*\)?/)) So it seems that it is not ok. I have the proper regexp that was tested at http://www.r

Re: is faster a regexp with multiple choices or a single one with lower case?

2015-01-08 Thread David Precious
On Wed, 7 Jan 2015 10:59:07 +0200 Shlomi Fish wrote: > Anyway, one can use the Benchmark.pm module to determine which > alternative is faster, but I suspect their speeds are not going to be > that much different. See: > > http://perl-begin.org/topics/optimising-and-profiling/ > > (Note: perl-beg

Re: is faster a regexp with multiple choices or a single one with lower case?

2015-01-08 Thread Luca Ferrari
Hi Bill, On Thu, Jan 8, 2015 at 1:36 AM, $Bill wrote: > Why not just ignore the case ? Sure it's an option. > Why does the script care what the case is ? Is there a rationale for > checking it ? Of course there's, and of course my script does different things depending on what I'm looking at.

Re: is faster a regexp with multiple choices or a single one with lower case?

2015-01-07 Thread Shlomi Fish
On Wed, 7 Jan 2015 07:56:18 + Andrew Solomon wrote: > Hi Luca, > > I haven't tested it, but my suspicion is that your first solution will > be faster because regular expressions (which don't contain variables) > are only compiled once, while you have a function call for every use > of lc. >

Re: is faster a regexp with multiple choices or a single one with lower case?

2015-01-06 Thread Andrew Solomon
~ /\.bat/i (which would also match BaT, BAt...) Andrew On Wed, Jan 7, 2015 at 7:45 AM, Luca Ferrari wrote: > Hi all, > this could be trivial, and I suspect the answer is that the regexp > engine is smart enough, but suppose I want to test the following: > > $extention =~ / \.bat | \.BAT

is faster a regexp with multiple choices or a single one with lower case?

2015-01-06 Thread Luca Ferrari
Hi all, this could be trivial, and I suspect the answer is that the regexp engine is smart enough, but suppose I want to test the following: $extention =~ / \.bat | \.BAT /x; is the following a better solution? $extension = lc $extension; $extension =~ / \.bat /x; In other words, when testing

Re: regexp puzzle

2014-03-08 Thread Bill McCormick
On 3/8/2014 12:05 AM, Bill McCormick wrote: I have the following string I want to extract from: my $str = "foo (3 bar): baz"; and I want to to extract to end up with $p1 = "foo"; $p2 = 3; $p3 = "baz"; the complication is that the \s(\d\s.+) is optional, so in then $p2 may not be set. getting

Re: RegExp

2014-03-08 Thread Jim Gibson
On Mar 8, 2014, at 4:50 AM, rakesh sharma wrote: > Hi all, > > how do you get all words starting with letter 'r' in a string. Try my @rwords = $string =~ /\br\w*?\b/g; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http:/

Re: RegExp

2014-03-08 Thread Janek Schleicher
Am 08.03.2014 13:50, schrieb rakesh sharma: how do you get all words starting with letter 'r' in a string. What have you tried so far? Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: RegExp

2014-03-08 Thread Shlomi Fish
Hello Rakesh, On Sat, 8 Mar 2014 18:20:48 +0530 rakesh sharma wrote: > Hi all, > how do you get all words starting with letter 'r' in a string. > thanks,rakesh > 1. Find all words in the sentence. Your idea of what is a word will need to be specified. 2

Re: RegExp

2014-03-08 Thread Shawn H Corey
On Sat, 8 Mar 2014 18:20:48 +0530 rakesh sharma wrote: > Hi all, > how do you get all words starting with letter 'r' in a string. > thanks,rakesh > /\br/ -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...

RegExp

2014-03-08 Thread rakesh sharma
Hi all, how do you get all words starting with letter 'r' in a string. thanks,rakesh

Re: regexp puzzle

2014-03-07 Thread Jim Gibson
On Mar 7, 2014, at 10:05 PM, Bill McCormick wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+) is optional, so in the

Re: regexp puzzle

2014-03-07 Thread shawn wilson
On Mar 8, 2014 1:41 AM, "shawn wilson" wrote: > Oh and per optional, just do (?:\([0-9]+).*\)? You should probably use do my @match = $str =~ / ([^]+) (?:\([0-9]+).*\)? ([a-z]+)/; my ($a, $b, $c) = (scalar(@match) == 3 ? @match : $match[0], undef, $match[1]); > ([^]+) \(([0-9]+).*\) ([a-z]+) >

Re: regexp puzzle

2014-03-07 Thread Bill McCormick
On 3/8/2014 12:41 AM, shawn wilson wrote: my $str = "foo (3 bar): baz"; my $test = "foo (3 bar): baz"; my ($p1, $p2, $p3) = $test =~ /([^]+) \(([0-9]+).*\) ([a-z]+)/; print "p1=[$p1] p2=[$p2] p3=[$p3]\n"; Use of uninitialized value $p1 in concatenation (.) or string at ./lock_report.pl line 1

Re: regexp puzzle

2014-03-07 Thread shawn wilson
([^]+) \(([0-9]+).*\) ([a-z]+) On Mar 8, 2014 1:07 AM, "Bill McCormick" wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+)

regexp puzzle

2014-03-07 Thread Bill McCormick
I have the following string I want to extract from: my $str = "foo (3 bar): baz"; and I want to to extract to end up with $p1 = "foo"; $p2 = 3; $p3 = "baz"; the complication is that the \s(\d\s.+) is optional, so in then $p2 may not be set. getting close was my ($p1, $p3) = $str =~ /^(.+):

Re: perl regexp performance - architecture?

2014-02-17 Thread Phil Smith
7;m seeing. Basically, I'm seeing perl performance significantly >>>> slower on my new systems than on my 6 year old systems. >>>> >>>> Here's some of the relevant details: >>>> >>>> + 6 year old server, 32 bit architecture,

Fwd: perl regexp performance - architecture?

2014-02-17 Thread Charles DeRykus
an on my 6 year old systems. >>> >>> Here's some of the relevant details: >>> >>> + 6 year old server, 32 bit architecture, CentOS5 perl5.8 >>> perl, and in particular regexp operations, perform reasonably fast. >>> >>> + Very new se

Re: perl regexp performance - architecture?

2014-02-17 Thread Phil Smith
: >> >> + 6 year old server, 32 bit architecture, CentOS5 perl5.8 >> perl, and in particular regexp operations, perform reasonably fast. >> >> + Very new server, 64 bit architecture, CentOS6, perl5.10 (and have tried >> perl5.18) >> perl, and in particular

Re: perl regexp performance - architecture?

2014-02-17 Thread Charles DeRykus
I'm > seeing. Basically, I'm seeing perl performance significantly slower on my > new systems than on my 6 year old systems. > > Here's some of the relevant details: > > + 6 year old server, 32 bit architecture, CentOS5 perl5.8 > perl, and in particular regexp op

perl regexp performance - architecture?

2014-02-17 Thread Phil Smith
ficantly slower on my new systems than on my 6 year old systems. Here's some of the relevant details: + 6 year old server, 32 bit architecture, CentOS5 perl5.8 perl, and in particular regexp operations, perform reasonably fast. + Very new server, 64 bit architecture, CentOS6, perl5.10 (and hav

Re: regexp as hash value?

2014-01-25 Thread Paul Johnson
On Sat, Jan 25, 2014 at 06:41:00PM +0100, Luca Ferrari wrote: > On Sat, Jan 25, 2014 at 4:12 PM, Paul Johnson wrote: > > > $ perl -E '$h = { a => qr/y/ }; say $_ =~ $h->{a} for qw(x y z)' > > Thanks, but then another doubt: having a look at > http://perl

Re: regexp as hash value?

2014-01-25 Thread Luca Ferrari
On Sat, Jan 25, 2014 at 4:12 PM, Paul Johnson wrote: > $ perl -E '$h = { a => qr/y/ }; say $_ =~ $h->{a} for qw(x y z)' Thanks, but then another doubt: having a look at http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators I dont understand how I can use the rege

Re: regexp as hash value?

2014-01-25 Thread Paul Johnson
On Sat, Jan 25, 2014 at 03:51:53PM +0100, Luca Ferrari wrote: > Hi, > I'm just wondering if it is possible to place a regexp as a value into > an hash so to use it later as something like: > > my $string =~ $hash_ref->{ $key }; > > Is it possible? Should I take i

regexp as hash value?

2014-01-25 Thread Luca Ferrari
Hi, I'm just wondering if it is possible to place a regexp as a value into an hash so to use it later as something like: my $string =~ $hash_ref->{ $key }; Is it possible? Should I take into account something special? Thanks, Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl

Re: regexp and parsing assistance

2013-06-09 Thread Noah
o fields $line =~ s/\S+\s\S+\s//; } my @fields = unpack('A2 A3 A11 A11 A18 A5 A5 A1',$line); Exactly what you need to do depends upon the exact nature of your data and how much it varies from line to line. Good luck! Thanks Jim, Here is the regexp I came up with. Works

Re: regexp and parsing assistance

2013-06-09 Thread Jim Gibson
On Jun 8, 2013, at 8:06 PM, Noah wrote: > Hi there, > > I am attempting to parse the following output and not quite sure how to do > it. The text is in columns and spaced out that way regardless if there are > 0 numbers in say col5 or Col 6 or not. If the column has an entry then I > want

regexp and parsing assistance

2013-06-08 Thread Noah
Hi there, I am attempting to parse the following output and not quite sure how to do it. The text is in columns and spaced out that way regardless if there are 0 numbers in say col5 or Col 6 or not. If the column has an entry then I want to save it to a variable if there is no entry then t

Re: character setts in a regexp

2013-01-14 Thread Charles DeRykus
On Sat, Jan 12, 2013 at 12:56 PM, Charles DeRykus wrote: > On Fri, Jan 11, 2013 at 2:01 PM, Christer Palm wrote: >> Hi! >> >> I have a perl script that parses RSS streams from different news sources and >> experience problems with national characters in a regexp funct

Re: character setts in a regexp

2013-01-14 Thread John SJ Anderson
On Fri, Jan 11, 2013 at 2:01 PM, Christer Palm wrote: > Do you have suggestions on this character issue? Is it possible to determine > the character set of a text efficiently? Is it other ways to solve the > problem? As far as other ways to solve the problem, my suggestion would be to not use r

Re: character setts in a regexp

2013-01-12 Thread Charles DeRykus
On Fri, Jan 11, 2013 at 2:01 PM, Christer Palm wrote: > Hi! > > I have a perl script that parses RSS streams from different news sources and > experience problems with national characters in a regexp function used for > matching a keyword list with the RSS data. > > Everyth

Re: character setts in a regexp

2013-01-11 Thread Brandon McCaig
On Fri, Jan 11, 2013 at 11:01:45PM +0100, Christer Palm wrote: > Hi! Hello, > I have a perl script that parses RSS streams from different > news sources and experience problems with national characters > in a regexp function used for matching a keyword list with the > RSS data.

Re: character setts in a regexp

2013-01-11 Thread Jim Gibson
On Jan 11, 2013, at 2:01 PM, Christer Palm wrote: > Hi! > > I have a perl script that parses RSS streams from different news sources and > experience problems with national characters in a regexp function used for > matching a keyword list with the RSS data. > > Everyth

character setts in a regexp

2013-01-11 Thread Christer Palm
Hi! I have a perl script that parses RSS streams from different news sources and experience problems with national characters in a regexp function used for matching a keyword list with the RSS data. Everything works fine with a simple regexp for plain english i.e. words containing the

Re: question of regexp or (another solution)

2012-12-15 Thread Dr.Ruud
On 2012-12-15 06:13, timothy adigun wrote: Using Dr., Ruud's data. This is another way of doing it: [solution using a hash] Realize that with keys(), the input order is not preserved. Another difference is that when a key comes back later, the hash solution will collide those, which is eithe

Re: question of regexp or (another solution)

2012-12-14 Thread *Shaji Kalidasan*
desseaux Cc: beginners@perl.org Sent: Saturday, 15 December 2012 10:43 AM Subject: Re: question of regexp or (another solution) Hi, On Fri, Dec 14, 2012 at 2:53 PM, samuel desseaux wrote: > Hi! > > I work in a library and i need to have several fields in one line > > E

Re: question of regexp or (another solution)

2012-12-14 Thread timothy adigun
Hi, On Fri, Dec 14, 2012 at 2:53 PM, samuel desseaux wrote: > Hi! > > I work in a library and i need to have several fields in one line > > Example > > I have this > > =995 \\$xPR$wLivre > =995 \\$bECAM$cECAM > =995 \\$n > =995 \\$oDisponible > =995 \\$kG1 42171 > > > and i want in one line >

Re: question of regexp or (another solution)

2012-12-14 Thread Dr.Ruud
On 2012-12-14 14:54, samuel desseaux wrote: =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n =995 \\$oDisponible =995 \\$kG1 42171 and i want in one line =995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre echo -n '1 a 1 b 1 c 2 x =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n

Re: question of regexp or (another solution)

2012-12-14 Thread samuel desseaux
i complete my email Hi! I work in a library and i need to have several fields in one line Example I have this =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n =995 \\$oDisponible =995 \\$kG1 42171 and i want in one line =995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre How could i

question of regexp or (another solution)

2012-12-14 Thread samuel desseaux
Hi! I work in a library and i need to have several fields in one line Example I have this =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n =995 \\$oDisponible =995 \\$kG1 42171 and i want in one line =995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre

Re: Scalar::Util::blessed() considers Regexp references to be blessed?

2012-01-23 Thread Brian Fraser
On Mon, Jan 23, 2012 at 2:12 AM, David Christensen < dpchr...@holgerdanske.com> wrote: > beginners@perl.org: > > While coding some tests tonight, I discovered that Scalar::Util::blessed() > considers Regexp references to be blessed. > > > Is this a bug or a featur

Scalar::Util::blessed() considers Regexp references to be blessed?

2012-01-22 Thread David Christensen
beginners@perl.org: While coding some tests tonight, I discovered that Scalar::Util::blessed() considers Regexp references to be blessed. Is this a bug or a feature? TIA, David 2012-01-22 21:07:57 dpchrist@p43400e ~/sandbox/perl $ cat blessed #! /usr/bin/perl # $Id: blessed,v 1.1 2012

Re: how to use regexp to match symbols

2011-06-13 Thread Sayth Renshaw
> I have a list of mp3 files in my computer and some of the file names consists > of  a bracket like this "darling I love [you.mp3" > I wish to check them for duplicates using the script below, but theres error > msg like this "Unmatched [ in regex; marked by <-- HERE in m/only one brace > here[

Re: how to use regexp to match symbols

2011-06-13 Thread Dr.Ruud
On 2011-06-13 14:05, eventual wrote: I have a list of mp3 files in my computer and some of the file names consists of a bracket like this "darling I love [you.mp3" I wish to check them for duplicates using the script below, but theres error msg like this "Unmatched [ in regex; marked by<-- HE

Re: how to use regexp to match symbols

2011-06-13 Thread John W. Krahn
by<-- HERE in m/only one brace here[<-- HERE anything.mp3/ at Untitled1 line 13." So how do I rewrite the regexp. Thanks. ## script ### #!/usr/bin/perl use strict; use warnings; use File::Find; my @datas = ("test.mp3" , "only one brace here[anything.mp3" , &q

Re: how to use regexp to match symbols

2011-06-13 Thread Rob Coops
msg like this "Unmatched [ in regex; marked by <-- HERE in m/only one > brace here[ <-- HERE anything.mp3/ at Untitled1 line 13." > > So how do I rewrite the regexp. > Thanks. > > ## script ### > #!/usr/bin/perl > use strict; > use warnings; > use File

how to use regexp to match symbols

2011-06-13 Thread eventual
ly one brace here[ <-- HERE anything.mp3/ at Untitled1 line 13."   So how do I rewrite the regexp. Thanks.   ## script ### #!/usr/bin/perl use strict; use warnings; use File::Find;   my @datas = ("test.mp3" , "only one brace here[anything.mp3" , "whatever.mp3&qu

Re: regexp validation (arbitrary code execution) (regexp injection)

2011-06-02 Thread Paul Johnson
On Wed, Jun 01, 2011 at 11:25:39PM +0200, Stanisław Findeisen wrote: > Suppose you have a collection of books, and want to provide your users > with the ability to search the book title, author or content using > regular expressions. > > But you don't want to let them execute any code. > > How wo

Re: regexp validation (arbitrary code execution) (regexp injection)

2011-06-02 Thread Randal L. Schwartz
> "Stanisław" == Stanisław Findeisen writes: Stanisław> But you don't want to let them execute any code. Unless "use re 'eval'" is in scope, /$a/ is safe even if $a came from an untrusted source, as long as you limit the run-time to a few seconds or so with an alarm. (Some regex can take ne

Re: regexp validation (arbitrary code execution) (regexp injection)

2011-06-02 Thread Rob Coops
2011/6/1 Stanisław Findeisen > Suppose you have a collection of books, and want to provide your users > with the ability to search the book title, author or content using > regular expressions. > > But you don't want to let them execute any code. > > How would you validate/compile/evaluate the us

Re: regexp validation (arbitrary code execution) (regexp injection)

2011-06-02 Thread Stanisław Findeisen
On 2011-06-02 14:27, Bob McConnell wrote: > From: Stanislaw Findeisen > >> Suppose you have a collection of books, and want to provide your users >> with the ability to search the book title, author or content using >> regular expressions. >> >> But you don't want to let them execute any code. >>

RE: regexp validation (arbitrary code execution) (regexp injection)

2011-06-02 Thread Bob McConnell
From: Stanislaw Findeisen > Suppose you have a collection of books, and want to provide your users > with the ability to search the book title, author or content using > regular expressions. > > But you don't want to let them execute any code. > > How would you validate/compile/evaluate the user

regexp validation (arbitrary code execution) (regexp injection)

2011-06-01 Thread Stanisław Findeisen
Suppose you have a collection of books, and want to provide your users with the ability to search the book title, author or content using regular expressions. But you don't want to let them execute any code. How would you validate/compile/evaluate the user provided regex so as to provide maximum

Re: regexp matching nummeric ranges

2010-12-13 Thread Randal L. Schwartz
> ""Kammen" == "Kammen van, Marco, Springer SBM NL" > writes: Kammen> What am I doing wrong?? Using a regex when something else would be much better. Stop trying to pound a nail in with a wrench handle. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 h

Re: Regexp delimiters

2010-12-08 Thread Jonathan Pool
> c:\>perl -wE "say $^V,$^O;$_='123456789';s§3(456)7§$1§;say" > v5.12.1MSWin32 > 1245689 My equivalent that works is: perl -wE "use utf8;my \$_='123456789';s§3(456)7§§\$1§;say;" 1245689 If I stop treating this section-sign delimiter as a bracketing delimiter, it fails: perl -wE "use utf8;m

Re: Regexp delimiters

2010-12-08 Thread Jonathan Pool
> Hm, what platform and perl version? 5.8.8 and 5.12.2 on RHEL, and 5.10.0 on OS X 10.6. > c:\>perl -Mutf8 -wE >"say $^V,$^O;$_='123456789';s§3(456)7§$1§;say" > Malformed UTF-8 character (unexpected continuation byte 0xa7, > with no preceding start byte) at -e line 1. Not the same err

Re: Regexp delimiters

2010-12-08 Thread C.DeRykus
On Dec 7, 9:38 am, p...@utilika.org (Jonathan Pool) wrote: > > Well, I have no idea why it does what it does, but I can tell you how to > > make it work: > > s¶3(456)7¶¶$1¶x; > > s§3(456)7§§$1§x; > Oops, sorry, yes there is: c:\>perl -Mutf8 -wE "say $^V,$^O;$_='123456789';s§3(456)7§$1§;say"

Re: Regexp delimiters

2010-12-08 Thread C.DeRykus
On Dec 7, 9:38 am, p...@utilika.org (Jonathan Pool) wrote: > > Well, I have no idea why it does what it does, but I can tell you how to > > make it work: > > s¶3(456)7¶¶$1¶x; > > s§3(456)7§§$1§x; Oops. yes there is: c:\>perl -Mutf8 -wE "say $^V,$^O;$_='123456789'; s§3(456)7§$1§;say" Malform

Re: Regexp delimiters

2010-12-08 Thread C.DeRykus
On Dec 7, 9:38 am, p...@utilika.org (Jonathan Pool) wrote: > > Well, I have no idea why it does what it does, but I can tell you how to > > make it work: > > s¶3(456)7¶¶$1¶x; > > s§3(456)7§§$1§x; > Hm, what platform and perl version? No errors here: c:\>perl -wE "say $^V,$^O;$_='1234567

Re: Regexp delimiters

2010-12-07 Thread Jonathan Pool
> Well, I have no idea why it does what it does, but I can tell you how to make > it work: > s¶3(456)7¶¶$1¶x; > s§3(456)7§§$1§x; Amazing. Thanks very much. This seems to contradict the documentation. The perlop man page clearly says that there are exactly 4 bracketing delimiters: "()", "[]", "{

Re: Regexp delimiters

2010-12-05 Thread Brian Fraser
That's probably because you are using what I sent, rather than what the OP did: > C:\>perl -E "s§3(456)7§$1§;" > Unrecognized character \x98 in column 16 at -e line 1. > > C:\>perl -Mutf8 -E "s§3(456)7§$1§;" > Substitution replacement not terminated at -e line 1. > > C:\>perl -E "s§3(456)7§§$1§;

Re: Regexp delimiters

2010-12-05 Thread Shawn H Corey
On 10-12-05 07:38 PM, Brian Fraser wrote: You have to tell perl to use UTF-8. Add this line to the top of your script(s): use utf8; See `perldoc utf8` for more details. Hm, I don't mean to step on your toes or anything, but he is already using utf8. The problem is with some utf

Re: Regexp delimiters

2010-12-05 Thread Brian Fraser
> > You have to tell perl to use UTF-8. Add this line to the top of your > script(s): > use utf8; > > See `perldoc utf8` for more details. Hm, I don't mean to step on your toes or anything, but he is already using utf8. The problem is with some utf8 characters being interpreted as a paired delimi

Re: Regexp delimiters

2010-12-05 Thread Shawn H Corey
On 10-12-05 05:58 PM, Brian Fraser wrote: Well, I have no idea why it does what it does, but I can tell you how to make it work: s¶3(456)7¶¶$1¶x; s§3(456)7§§$1§x; For whatever reason, Perl is treating those character as an 'opening' delimiter[0], so that when you write s¶3(456)7¶$1¶;, you are te

Re: Regexp delimiters

2010-12-05 Thread Brian Fraser
Well, I have no idea why it does what it does, but I can tell you how to make it work: s¶3(456)7¶¶$1¶x; s§3(456)7§§$1§x; For whatever reason, Perl is treating those character as an 'opening' delimiter[0], so that when you write s¶3(456)7¶$1¶;, you are telling Perl that the regex part is delimited

Regexp delimiters

2010-12-05 Thread Jonathan Pool
The perlop document under "s/PATTERN/REPLACEMENT/msixpogce" says "Any non-whitespace delimiter may replace the slashes." I take this to mean that any non-whitespace character may be used instead of a slash. However, I am finding that some non-whitespace characters cause errors. For example, us

Re: regexp matching nummeric ranges

2010-11-30 Thread Rob Dixon
On 30/11/2010 06:39, Uri Guttman wrote: "GK" == Guruprasad Kulkarni writes: GK> Here is another way to do it: GK> /^127\.0\.0\.([\d]|[1-9][\d]|[1][\d][\d]|[2]([0-4][\d]|[5][0-4]))$/) { why are you putting single chars inside a char class? [\d] is the same as \d and [1] is just 1. A

Re: regexp matching nummeric ranges

2010-11-29 Thread John W. Krahn
Rob Dixon wrote: On 29/11/2010 23:46, John W. Krahn wrote: As Rob said [2..254] is a character class that matches one character (so "127.0.0.230" should match also.) You also don't anchor the pattern so something like '765127.0.0.273646' would match as well. What you need is something like thi

Re: regexp matching nummeric ranges

2010-11-29 Thread Uri Guttman
> "GK" == Guruprasad Kulkarni writes: GK> Here is another way to do it: GK> /^127\.0\.0\.([\d]|[1-9][\d]|[1][\d][\d]|[2]([0-4][\d]|[5][0-4]))$/) { why are you putting single chars inside a char class? [\d] is the same as \d and [1] is just 1. also please don't quote entire emails below

RE: regexp matching nummeric ranges

2010-11-29 Thread Kammen van, Marco, Springer SBM NL
>-Original Message- >From: John W. Krahn [mailto:jwkr...@shaw.ca] >Sent: Tuesday, November 30, 2010 12:47 AM >To: Perl Beginners >Subject: Re: regexp matching nummeric ranges >As Rob said [2..254] is a character class that matches one character (so >"127.

Re: regexp matching nummeric ranges

2010-11-29 Thread Guruprasad Kulkarni
Hi Marco, Here is another way to do it: #!/usr/bin/perl use strict; use warnings; my $ip = "127.0.0.1"; if ($ip =~ /^127\.0\.0\.([\d]|[1-9][\d]|[1][\d][\d]|[2]([0-4][\d]|[5][0-4]))$/) { print "IP Matched!\n";; } else { print "No Match!\n"; } On Tue, Nov 30, 2010 at 11:21 AM, Rob Dixon wrote:

Re: regexp matching nummeric ranges

2010-11-29 Thread Rob Dixon
On 29/11/2010 23:46, John W. Krahn wrote: Kammen van, Marco, Springer SBM NL wrote: Dear List, Hello, I've been struggeling with the following: #!/usr/bin/perl use strict; use warnings; my $ip = ("127.0.0.255"); if ($ip =~ /127\.0\.0\.[2..254]/) { print "IP Matched!\n";; } else { print "

Re: regexp matching nummeric ranges

2010-11-29 Thread John W. Krahn
Kammen van, Marco, Springer SBM NL wrote: Dear List, Hello, I've been struggeling with the following: #!/usr/bin/perl use strict; use warnings; my $ip = ("127.0.0.255"); if ($ip =~ /127\.0\.0\.[2..254]/) { print "IP Matched!\n";; } else { print "No Match!\n"; } For a reason i don't

Re: regexp matching nummeric ranges

2010-11-29 Thread Rob Dixon
On 29/11/2010 14:22, Kammen van, Marco, Springer SBM NL wrote: Dear List, I've been struggeling with the following: #!/usr/bin/perl use strict; use warnings; my $ip = ("127.0.0.255"); if ($ip =~ /127\.0\.0\.[2..254]/) { print "IP Matched!\n";; } else { print "No Match!\n"; } For a rea

regexp matching nummeric ranges

2010-11-29 Thread Kammen van, Marco, Springer SBM NL
Dear List, I've been struggeling with the following: #!/usr/bin/perl use strict; use warnings; my $ip = ("127.0.0.255"); if ($ip =~ /127\.0\.0\.[2..254]/) { print "IP Matched!\n";; } else { print "No Match!\n"; } For a reason i don't understand: 127.0.0.1 doesn't match as expected... Eve

Re: Parsing file and regexp

2010-02-19 Thread Shawn H Corey
olivier.scalb...@algosyn.com wrote: > $ cat test.txt > keyword1 word1, word2 > word3; > blabla > > blabla > > > keyword2 > word4, word5, > word6, word7, word8, > word9; > > bla bla > bla bla > > keyword1 > word10, word11; #!/usr/bin/perl use strict; use warnings; use Data:

Re: Parsing file and regexp

2010-02-19 Thread olivier.scalb...@algosyn.com
Uri Guttman wrote: > > please show your code. there is no way to help otherwise. s/// is not a > > pattern matcher but a substitution operator. it uses regexes and can be > > used to parse things. > > > > uri > > Here it is ... $ cat test.txt keyword1 word1, word2 word3; blabla blabla ke

Re: Parsing file and regexp

2010-02-19 Thread olivier.scalb...@algosyn.com
(Sorry but I have problem with my ISP, so I repost !) Uri Guttman wrote: > > how do you know when a keyword section begins or ends? how large is this > > file? could free text have keywords? i see a ; to end a word list but > > that isn't enough to properly parse this if you have 'free text'. > >

Re: Parsing file and regexp

2010-02-13 Thread Uri Guttman
> "osc" == olivier scalb...@algosyn com > writes: osc> keywordA word1, word2, word3; osc> Here we can have some free text osc> ... osc> ... osc> keywordB word4, osc> word5, word6, word7, word8, osc> word9, word10; osc> KeywordA osc

Parsing file and regexp

2010-02-13 Thread olivier.scalb...@algosyn.com
Hello, I need to extract info from some text files. And I want to do it with Perl ! The file I need to parse has the following layout: keywordA word1, word2, word3; Here we can have some free text ... ... keywordB word4, word5, word6, word7, word8, word9, word10

Re: Regexp to remove spaces

2009-12-29 Thread Dr.Ruud
sftriman wrote: Dr.Ruud: sub trim { ... }#trim You're missing the tr to squash space down To trim() is to remove from head and tail only. Just use it as an example to build a "trim_and_normalize()". So I think it can boil down to: sub fixsp7 { s#\A\s+##, s#\s+\z##, tr/ \t\n\r\f/ /

Re: Regexp to remove spaces

2009-12-28 Thread Shawn H Corey
sftriman wrote: > So I think it can boil down to: > > sub fixsp7 { > s#\A\s+##, s#\s+\z##, tr/ \t\n\r\f/ /s foreach @_; > return; > } sub fixsp7 { tr/ \t\n\r\f/ /s, s#\A\s##, s#\s\z## foreach @_; return; } Placing the tr/// first reduces the number of characters scanned for s#\s\z## which m

Re: Regexp to remove spaces

2009-12-28 Thread sftriman
On Dec 23, 2:31 am, rvtol+use...@isolution.nl (Dr.Ruud) wrote: > sftriman wrote: > > 1ST PLACE - THE WINNER:  5.0s average on 5 runs > > > # Limitation - pointer > > sub fixsp5 { > > ${$_[0]}=~tr/ \t\n\r\f/ /s; > > ${$_[0]}=~s/\A //; > > ${$_[0]}=~s/ \z//; > > } > > Just decide to change in-place,

Re: Regexp to remove spaces

2009-12-23 Thread Dr.Ruud
sftriman wrote: 1ST PLACE - THE WINNER: 5.0s average on 5 runs # Limitation - pointer sub fixsp5 { ${$_[0]}=~tr/ \t\n\r\f/ /s; ${$_[0]}=~s/\A //; ${$_[0]}=~s/ \z//; } Just decide to change in-place, based on the defined-ness of wantarray. sub trim { no warnings 'uninitialized'; if

Re: Regexp to remove spaces

2009-12-22 Thread sftriman
a 176 byte string for testing, and ran each method 1,000,000 times to time the speed. The winner is: 3 regexp, using tr for intra-string spaces. I found I could make this even faster using a pointer to the variable versus passing in the variable as a local input parameter, modifying, then returnin

Re: Regexp to remove spaces

2009-12-21 Thread Jim Gibson
At 6:11 PM +0800 12/21/09, Albert Q wrote: 2009/12/20 Dr.Ruud > > For a multi-line buffer you can do it like this: perl -wle ' my $x = <<"EOT"; 123456 \t abc def \t\t\t\t\t\t\t\t *** *** *** \t EOT s/^\s+//mg, s/\s+$//mg, s/[^\S\n]+/ /g for $x; I kno

Re: Regexp to remove spaces

2009-12-21 Thread Albert Q
2009/12/20 Dr.Ruud > > sftriman wrote: > >> I use this series of regexp all over the place to clean up lines of >> text: >> >> $x=~s/^\s+//g; >> $x=~s/\s+$//g; >> $x=~s/\s+/ /g; >> >> in that order, and note the final one replace \s+ wit

Re: Regexp to remove spaces

2009-12-21 Thread Dr.Ruud
Shawn H Corey wrote: $text =~ tr{\t}{ }; $text =~ tr{\n}{ }; $text =~ tr{\r}{ }; $text =~ tr{\f}{ }; $text =~ tr{ }{ }s; That can be written as: tr/\t\n\r\f/ /, tr/ / /s for $text; But it doesn't remove all leading nor all trailing spaces. -- Ruud -- To unsubscribe, e-mail: beginners-uns

Re: Regexp to remove spaces

2009-12-21 Thread Dr.Ruud
sftriman wrote: I use this series of regexp all over the place to clean up lines of text: $x=~s/^\s+//g; $x=~s/\s+$//g; $x=~s/\s+/ /g; in that order, and note the final one replace \s+ with a single space. The g-modifier on the first 2 is bogus (unless you would add an m-modifier). I

Re: Regexp to remove spaces

2009-12-20 Thread Robert Wohlfarth
On Sat, Dec 19, 2009 at 9:13 PM, sftriman wrote: > I use this series of regexp all over the place to clean up lines of > text: > > $x=~s/^\s+//g; > $x=~s/\s+$//g; > $x=~s/\s+/ /g; > > in that order, and note the final one replace \s+ with a single space. > >

Re: Regexp to remove spaces

2009-12-20 Thread Shawn H Corey
John W. Krahn wrote: > That can be reduced to: > > $text =~ tr/ \t\n\r\f/ /s; > > But that still doesn't remove leading and trailing whitespace so add two > more lines: > > $text =~ tr/ \t\n\r\f/ /s; > $text =~ s/\A //; > $text =~ s/ \z//; That was left as an exercise to the reader. Come now,

  1   2   3   4   5   6   7   8   9   10   >