Re: regex matching statements

2024-06-19 Thread Levi Elias Nystad-Johansen via beginners
Hi, Yes, they are the same. I like to use $_ only when the data comes in $_ naturally. Like in a for loop: for (qw< abc >) { if ( !/\w+\d+/ ) { print "not matched"; } } Otherwise, I have to write $_, then I prefer to name the variable something descriptive instead. Makes the code

regex matching statements

2024-06-18 Thread Jeff Peng via beginners
Hello list, are these statements the same in perl? $ perl -le '$_="abc";if (!/\w+\d+/){print "not matched"}' not matched $ perl -le '$_="abc";if ($_ !~ /\w+\d+/){print "not matched"}' not matched or which is the better one? Thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Re: regex

2024-01-24 Thread karl
Mike: > I stand properly scolded. I didn't want to scold anyone, it seems I expressed myself wrong. Sorry for that. Regards, /Karl Hammar -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: regex

2024-01-23 Thread Mike
I stand properly scolded. Mike On 1/23/24 07:01, k...@aspodata.se wrote: Please stop using my mail address when replying, I'm on the list and don't want two copies of the same mail (it's not about you Mike). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

Re: regex

2024-01-23 Thread karl
Please stop using my mail address when replying, I'm on the list and don't want two copies of the same mail (it's not about you Mike). Mike > Why is my Perl not working on that command? > > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;' > Unescaped left brace in regex is illegal

Re: regex

2024-01-22 Thread Mike
Why is my Perl not working on that command? $ perl -e 'exit(10) if "aaa"=~/a{,2}/;' Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/a{ <-- HERE ,2}/ at -e line 1. $ But this works: $ perl -e 'exit(10) if "aaa"=~/a{0,2}/;' $ $ echo

Re: regex

2024-01-22 Thread armando perez pena
have a problem and you say I will solve it with regular expressions then you have two problems. Ánimos! Saludos From: Claude Brown via beginners Sent: Monday, January 22, 2024 10:49:50 PM To: k...@aspodata.se ; beginners@perl.org Subject: RE: regex Jorge

RE: regex

2024-01-22 Thread Claude Brown via beginners
Jorge, Expanding on Karl's answer (and somewhat labouring his point) consider these examples: $a =~ /Jorge/ $a =~ /^Jorge/ $a =~ /Jorge$/ $a =~ /^Jorge$/ This shows that regex providing four different capabilities: - detect "Jorge" anywhere in the string - detect "Jorg

Re: regex

2024-01-22 Thread Levi Elias Nystad-Johansen via beginners
I agree that this is confusing, and I think many resources describing regex in unhelpful ways is partly to blame. descriptions like "pattern that matches against a string" and similar. this implies that a regex has to match the string, but this is not the case. a regex does not hav

Re: regex

2024-01-22 Thread Andy Bach
ot;=~/a{,2}/;' Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/a{ <-- HERE ,2}/ at -e line 1. and % perldoc perlre says Quantifiers Quantifiers are used when a particular portion of a pattern needs to match a certain number (or numbers) of times

Re: regex

2024-01-22 Thread karl
Jorge Almeida: > On Mon, 22 Jan 2024 at 13:00, wrote: > > Jorge Almeida: > > > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;' ... > > {,n}Match at most n times ... > Yes, I read it (several times). I still don't understand it (I understand > what you're saying, and I trust you're right, I just

Re: regex

2024-01-22 Thread karl
Jorge Almeida: > Please help me to understand this: > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;' > $ echo $? > $ 10 In man perlre, under "Regular Expressions" it says: {,n}Match at most n times So /a{,2}/ matches "", "a", and "aa" and is ignorant about what comes before and after

regex

2024-01-22 Thread Jorge Almeida
Please help me to understand this: $ perl -e 'exit(10) if "aaa"=~/a{,2}/;' $ echo $? $ 10 Thanks Jorge Almeida

Re: escape character in regex

2022-10-10 Thread John W. Krahn
On 2022-10-10 18:12, Henrik Park wrote: I know "/" is a special character for regex, which should be escaped. But if I put "/" in a variable and use the variable in regex, then it doesn't need the explicit escape. Like this one: $ perl -le '$delimiter="/"; $s

escape character in regex

2022-10-10 Thread Henrik Park
Hello I know "/" is a special character for regex, which should be escaped. But if I put "/" in a variable and use the variable in regex, then it doesn't need the explicit escape. Like this one: $ perl -le '$delimiter="/"; $str="hello/world/buddy"; @

Re: about a regex

2021-12-31 Thread wagsworld48 via beginners
Add ^ as [^a-zA-Z0-9] Though there are probably a number of different ways to approach RegEx… Wags ;) WagsWorld Hebrews 4:15 Ph(primary) : 408-914-1341 Ph(secondary): 408-761-7391 On Dec 31, 2021, 20:22 -0800, Piper H , wrote: > Hello > > I know [a-zA-Z0-9] means words and numbers. >

Re: about a regex

2021-12-31 Thread Piper H
] > > You could do > > $string !~ m/[a-zA-Z0-9]/ > > > On Fri, Dec 31, 2021 at 10:23 PM Piper H wrote: > >> Hello >> >> I know [a-zA-Z0-9] means words and numbers. >> But what's the reverse of this regex? >> >> Thank you. >> >

Re: about a regex

2021-12-31 Thread Adam Hopkins
; But what's the reverse of this regex? > > Thank you. >

about a regex

2021-12-31 Thread Piper H
Hello I know [a-zA-Z0-9] means words and numbers. But what's the reverse of this regex? Thank you.

Re: Regex to detect natural language fragment

2021-09-14 Thread Julius Hamilton
Thanks very much. @Chankey Pathak, which of those libraries does you recommend for this task? Best regards, Julius On Tue, Sep 14, 2021 at 2:33 AM Ken Peng wrote: > Or use GPT-3 who has a free online API. > https://openai.com/blog/openai-api/ > > regards > > On Mon, Sep 13, 2021 at 11:42 PM

Re: Regex to detect natural language fragment

2021-09-13 Thread Ken Peng
Or use GPT-3 who has a free online API. https://openai.com/blog/openai-api/ regards On Mon, Sep 13, 2021 at 11:42 PM Chankey Pathak wrote: > You can look into NLP https://metacpan.org/search?q=nlp > > On Mon, 13 Sept 2021 at 21:04, Julius Hamilton < > juliushamilton...@gmail.com> wrote: > >>

Re: Regex to detect natural language fragment

2021-09-13 Thread Chankey Pathak
You can look into NLP https://metacpan.org/search?q=nlp On Mon, 13 Sept 2021 at 21:04, Julius Hamilton wrote: > Hey, > > I'm not sure if this is possible, and if it's not, I'll explore a better > way to do this. > > I would like to write a script which analyzes if a line of text is > (likely) a

Regex to detect natural language fragment

2021-09-13 Thread Julius Hamilton
Hey, I'm not sure if this is possible, and if it's not, I'll explore a better way to do this. I would like to write a script which analyzes if a line of text is (likely) a broken natural language sentence, i.e., it is probably part of a sentence, even if the start or end is not present, rather

Re: regex help - only one value returned

2020-12-02 Thread Jim Gibson
>> would give output: >> >> match3='Miss Jayne Doe' '' > Perfect, thank you. > > I can't ignore $2 as it's in a loop with other regex that genuinely returns > multiple matches. The amendment to the REGEX worked perfectly. It is always best to save the results of a

Re: regex help - only one value returned

2020-12-02 Thread Gary Stainburn
)'. For example: print "match3='$1' '$2'\n" if ($T=~/^((?:mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi); would give output: match3='Miss Jayne Doe' '' Perfect, thank you. I can't ignore $2 as it's in a loop with other regex that genuinely returns multiple matches.  The amendment to the REGEX worked

Re: regex help - only one value returned

2020-12-02 Thread Vlado Keselj
$2'\n" if ($T=~/^((?:mr|mrs|miss|dr|prof|sir) .{5,}?)\n/smi); would give output: match3='Miss Jayne Doe' '' On Wed, 2 Dec 2020, Gary Stainburn wrote: > I have an array of regex expressions that I apply to text returned from > tesseract. > > Each match that I get then gets stored

regex help - only one value returned

2020-12-02 Thread Gary Stainburn
I have an array of regex expressions that I apply to text returned from tesseract. Each match that I get then gets stored for future processing. However, I'm struggling with one regex. The problem is that: 1) with brackets round the titles it returns two matches. 2) without brackets

Re: Help me with a regex problem

2019-10-26 Thread Dermot
first looks > like an IP address and the second looks like a file path. In other > words I can't distinguish the difference between these two "types". > > > > I know how to write regex to match each line, but don't get the good > result > > with one regex to m

Re: Help me with a regex problem

2019-10-25 Thread John W. Krahn
looks like an IP address and the second looks like a file path. In other words I can't distinguish the difference between these two "types". I know how to write regex to match each line, but don't get the good result with one regex to match both lines. Can you help? Perhaps if

Re: Help me with a regex problem

2019-10-25 Thread Andy Bach
ath, right? if ( $entry =~ m#([\d.]+)\s+(/\S+)# ) { my ($ip, $path) = ($1, $2); print "IP $ip asked for path $path\n"; On Fri, Oct 25, 2019 at 5:28 AM Илья Рассадин wrote: > For example, this regex > > /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/ > >

Re: Help me with a regex problem

2019-10-25 Thread Benjamin S Pendygraft II
That is a backslash followed by a forward slash. The backslash tells the regex parser to treat the next character as a literal character. Useful for matching periods, question marks, brackets, etc. A period matches any character once and an asterisk matches the previous character any number

Re: Help me with a regex problem

2019-10-25 Thread X Dungeness
my $n = '[0-9]{1,3}'; if ( =~ ( m[ (?:$n\.){3} $n \s+ \S+ ]x ) { # match } On Fri, Oct 25, 2019 at 3:37 AM Maggie Q Roth wrote: > what's V.*? > > Maggie > > On Fri, Oct 25, 2019 at 6:28 PM Илья Рассадин wrote: > >> For example, this regex >> >

Re: Help me with a regex problem

2019-10-25 Thread Maggie Q Roth
what's V.*? Maggie On Fri, Oct 25, 2019 at 6:28 PM Илья Рассадин wrote: > For example, this regex > > /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/ > > On 25.10.2019 13:23, Maggie Q Roth wrote: > > Hello > > > > There are two primary types of li

Re: Help me with a regex problem

2019-10-25 Thread Илья Рассадин
For example, this regex /(?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s+(?\/.*)/ On 25.10.2019 13:23, Maggie Q Roth wrote: Hello There are two primary types of lines in the log: 60.191.38.xx        / 42.120.161.xx       /archives/1005 I know how to write regex to match each line

Help me with a regex problem

2019-10-25 Thread Maggie Q Roth
Hello There are two primary types of lines in the log: 60.191.38.xx/ 42.120.161.xx /archives/1005 I know how to write regex to match each line, but don't get the good result with one regex to match both lines. Can you help? Thanks, Maggie

Re: Common regex for timedate

2018-11-19 Thread Asad
7292 > $ date -d '05-JUL-18 10:19:42 ' "+%s" > 1530803982 > > That's ignoring TZ > > On Tue, Nov 13, 2018 at 5:38 PM Asad wrote: > >> Hi Andy , >> >> thanks for the reply . Yes the purpose is to compare the >> timestamps ans yes these ar

Re: Common regex for timedate

2018-11-14 Thread Andy Bach
> thanks for the reply . Yes the purpose is to compare the > timestamps ans yes these are the only two formats . > > Thanks, > > On Wed, Nov 14, 2018 at 2:48 AM Andy Bach wrote: > >> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 >> Calling

Re: Common regex for timedate

2018-11-13 Thread Asad
12:28:12,447849 +02: > > > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9] > > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > Right as your first string has word chars for the month, not digits. So, a > straight forward, if

Re: Common regex for timedate

2018-11-13 Thread Andy Bach
Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 Calling apply.sql on 17.10.18 12:28:12,447849 +02: > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9] > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: Right as your first string has w

Re: Common regex for timedate

2018-11-13 Thread Дмитрий Ананьевский
On Mon, 12 Nov 2018 18:18:12 +0530 Asad wrote: > Hi all , > >I have two stings from logfile how can we have a common regex so > that its parse datetime details for further parsing ; > > Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 > Calling apply.

Re: Common regex for timedate

2018-11-12 Thread David Y Wagner via beginners
You could change the first portion of RegEx to \d{2}[.\-](\d{2}|\D{3})[.\-] This could cover all the valid Month codes, but this will look for the hyphen or period and two digit month or three non digits and then the the hyphen or period following. There is much more you could do

Common regex for timedate

2018-11-12 Thread Asad
Hi all , I have two stings from logfile how can we have a common regex so that its parse datetime details for further parsing ; Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 Calling apply.sql on 17.10.18 12:28:12,447849 +02: I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread armando perez pena
tetime from datetime import timedelta Header = "*" f3 = open ( r"D:\QI\logA.txt", 'r' ) string = f3.read () regex = re.compile ( "\n" ) st = regex.sub ( " ", string ) st1 = st.split ( " " ) if re

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Chris Fedde
= open ( r"D:\QI\logA.txt", 'r' ) > string = f3.read () > regex = re.compile ( "\n" ) > st = regex.sub ( " ", string ) > st1 = st.split ( " " ) > > if re.search ('ERR-1:', st ): > x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Asad
Hi , Yes i have the code : import re import datetime from datetime import timedelta Header = "*" f3 = open ( r"D:\QI\logA.txt", 'r' ) string = f3.read () regex = re.compile ( "\n" ) st = regex.sub

Re: How to compare timestamp in two different files(regex)

2018-10-25 Thread Jim Gibson
(Please reply to the list.) If you have written code that extracts the date and time from the ‘LOG flle opened’ lines in the log file, then please show us your code. You seem to be asking other people to write your program for you. You will get better help if you appear to be making an effort

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Jim Gibson
> On Oct 24, 2018, at 9:54 PM, Asad wrote: > > Thank all now I am able to progress : > > file1 i am able to extract the start and end timestamp > file 2 i am able to extract the timestamp > > used the following > my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Asad
Thank all now I am able to progress : file1 i am able to extract the start and end timestamp file 2 i am able to extract the timestamp used the following my $t1 = Time::Piece->strptime('Feb 23 01:10:28 2018', '%b %d %H:%M:%S %Y'); coming from file1 my $t2 = Time::Piece->strptime('02/23/18

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Martin McCormick
Someone brought to my attention that I had failed to define a couple of variables in the sample code I posted and they were quite right. I don't mind sharing my work but the entire application I wrote to get a brief local weather summary is 242 lines and I was trying to stay close to the topic,

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Andy Bach
===> I am using the following regex : ([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4}) > Both are working as expected I would like to know if these are good regex or it can be better , please suggest . Concurring with the others, your setting yourself up for t

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Chris Fedde
I cannot emphasize enough how fragile the perhaps obvious regex based comparisons of timestamps can be. I second the approach demonstrated by Илья Рассадин above. There are subtle and difficult to debug problems buried in timestamps. Not least of which is locale ambiguity, discontinuities like

Re: How to compare timestamp in two different files(regex)

2018-10-24 Thread Olivier
Hi, > Thank you all for the reply it is working for me . > > 1) for 02/23/18 01:10:33 ==> I am using the following regex > \d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] > 2) Feb 23 01:10:28 2018 > > I am using the following regex : > ([A-Z][a-z]{2}\s)([0-9]{2}

Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Asad
Thank you all for the reply it is working for me . 1) for 02/23/18 01:10:33 ==> I am using the following regex \d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] 2) Feb 23 01:10:28 2018 > I am using the following regex : ([A-Z][a-z]{2}\s)([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[

Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Andy Bach
> first hurdle is how do I extract this Feb 23 01:10:28 2018 from file1 which regex Look at perldoc -f stat ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); Not

Re: How to compare timestamp in two different files(regex)

2018-10-23 Thread Asad
Hi All , first hurdle is how do I extract this Feb 23 01:10:28 2018 from file1 which regex can I use ? convert it into epoch then regex for 02/23/18 01:10:33 is required ? convert into epoch So if you can suggest the correct regex for both

Re: Regex for date

2018-08-25 Thread Chris Charley
"Asad" wrote in message news:cag3lskh4dphjg18c-jxmo8bcqfd+vix5tep1ytsp4_6pd6z...@mail.gmail.com... Hi All , I need a regex to match the date : Sat Aug 25 08:41:03 2018 and covert into a format :'%m/%d/%Y %H:%M:%S' Thanks, -- Asad Hasan +91 9582111698 Hello

Re: Regex for date

2018-08-25 Thread Jim Gibson
Many Perl modules have been written to parse and manipulate dates and times. Some come with Perl; others are available at www.cpan.org. Check out the Date::Manip, Date::Parse, or DateTime modules. > On Aug 25, 2018, at 4:06 AM, Asad wrote: > > Hi All , > > I need a

Re: Regex for date

2018-08-25 Thread Asad
Thanks, I'll check them out. On Sat, Aug 25, 2018 at 4:53 PM Home Linux Info wrote: > > Hello, > > Maybe not the most beautiful regex out there, hey I'm a noob, but it does > the job right: > ([A-Z][a-z]{2}\s)|([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4}) > You can sta

Re: Regex for date

2018-08-25 Thread Home Linux Info
Hello, Maybe not the most beautiful regex out there, hey I'm a noob, but it does the job right: ([A-Z][a-z]{2}\s)|([0-9]{2}\s[0-2][0-9](:[0-5][0-9]){2}\s[0-9]{4}) You can start from here and find a nicer form of this regex. On 8/25/18 2:06 PM, Asad wrote: Hi All ,           I need  a regex

Re: Regex for date

2018-08-25 Thread Mike Flannigan
Really, no attempt to do it yourself? Mike On 8/25/2018 6:06 AM, beginners-digest-h...@perl.org wrote: Hi All ,           I need  a regex to match the date : Sat Aug 25 08:41:03 2018 and covert into a format :  '%m/%d/%Y %H:%M:%S' Thanks, -- Asad Hasan

Regex for date

2018-08-25 Thread Asad
Hi All , I need a regex to match the date : Sat Aug 25 08:41:03 2018 and covert into a format : '%m/%d/%Y %H:%M:%S' Thanks, -- Asad Hasan +91 9582111698

Re: regex to get the rpm name version

2018-08-09 Thread Andy Bach
-]{3,}[0-9]*" to get the package name, it > needs a little more work for right now it gets the last dash and first > digit of package version. Then you can try "*([^a-zA-Z_+-]{3,})(.\d{1,})* > ". > The first regex gives the following result: > *binutils-2* > *compat-libcap1* &

Re: regex to get the rpm name version

2018-08-09 Thread Home Linux Info
Hello, You can begin with "*[a-zA-Z_+-]{3,}[0-9]*" to get the package name, it needs a little more work for right now it gets the last dash and first digit of package version. Then you can try "*([^a-zA-Z_+-]{3,})(.\d{1,})*". The first regex gives the following result: /b

Re: regex to get the rpm name version

2018-07-27 Thread Shlomi Fish
Hi Asad, On Fri, 27 Jul 2018 18:24:39 +0530 Asad wrote: > Hi All , > > I want to get a regex to actually get the rpm name and version for > comparison : > > > binutils-2.23.52.0.1-12.el7.x86_64", > compat-libcap1-1.10-3.el7.x86_64" >

Re: regex to get the rpm name version

2018-07-27 Thread Chas. Owens
But if you have to use a regex, I suggest using the /x modifier to make it easier to read an maintain the regex: #!/usr/bin/perl use strict; use warnings; for my $s (qw/binutils-2.23.52.0.1-12.el7.x86_64 compat-libcap1-1.10-3.el7.x86_64 compat-libstdc++-33-3.2.3-71.el7.i686/) { my ($name

RE: regex to get the rpm name version

2018-07-27 Thread Duncan Ferguson
I would suggest you change your approach and user the query mode of RPM to get your information instead of build up a regexp: rpm -qa --queryformat "%{NAME}\n" Duncs From: Asad [mailto:asad.hasan2...@gmail.com] Sent: 27 July 2018 13:55 To: beginners@perl.org Subject: regex to g

Re: regex to get the rpm name version

2018-07-27 Thread Chas. Owens
I don't think a regex is the simplest and most maintainable way to get this information. I think it is probably better to take advantage of the structure of the string to discard and find information: #!/usr/bin/perl use strict; use warnings; for my $s (qw/binutils-2.23.52.0.1-12.el7.x86_64

regex to get the rpm name version

2018-07-27 Thread Asad
Hi All , I want to get a regex to actually get the rpm name and version for comparison : binutils-2.23.52.0.1-12.el7.x86_64", compat-libcap1-1.10-3.el7.x86_64" compat-libstdc++-33-3.2.3-71.el7.i686 (^[a-zA-Z0-9\-]*)\-\d' First part of the regular expression is ^[a-zA-Z0-9

Re: regex matches Chinese characters

2018-07-26 Thread Shlomi Fish
Hi Lauren, On Fri, 27 Jul 2018 11:28:42 +0800 "Lauren C." wrote: > greetings, > > I was doing the log statistics stuff using perl. > There are chinese characters in log items. > I tried with regex to match them, but got no luck. > > $ perl -mstrict -le 'my $

Re: regex matches Chinese characters

2018-07-26 Thread Lauren C.
oops that's perfect. thanks Shlomi. On 2018/7/27 星期五 PM 1:26, Shlomi Fish wrote: Hi Lauren, On Fri, 27 Jul 2018 11:28:42 +0800 "Lauren C." wrote: greetings, I was doing the log statistics stuff using perl. There are chinese characters in log items. I tried with regex to match the

regex matches Chinese characters

2018-07-26 Thread Lauren C.
greetings, I was doing the log statistics stuff using perl. There are chinese characters in log items. I tried with regex to match them, but got no luck. $ perl -mstrict -le 'my $char="汉语"; print "it is chinese" if $char =~ /\p{Han}+/' $ perl -mstrict -mutf8 -le '

Re: help with another regex

2018-07-17 Thread Lauren C.
I think reading the official tutorial from begin is not that comfortable to a newbie. I bought a book "Learning Perl, 6th Edition" for studying step by step. thanks. On 2018/7/18 星期三 AM 9:08, Uri Guttman wrote: also i always recommend reading the entire perl FAQ as there are many

Re: help with another regex

2018-07-17 Thread Uri Guttman
again but more slowly to learn the key things and practice them. then reread sections you need to know better as the core stuff will be somewhat familiar by then and you can delve deeper. and after you are done with the tutorial, read the full reference doc on the subject! the regex reference

Re: help with another regex

2018-07-17 Thread Lauren C.
I did read them, but got no deep impression unless I met the issue. :) Uri Guttman 写道: On 07/17/2018 08:46 PM, Lauren C. wrote: Thanks Gil. I think i know the difference of "\w+" and "\w*" now. lauren, did you read the perlretut document? if not, you should. it covers quantifiers early on

Re: help with another regex

2018-07-17 Thread Uri Guttman
On 07/17/2018 08:46 PM, Lauren C. wrote: Thanks Gil. I think i know the difference of "\w+" and "\w*" now. lauren, did you read the perlretut document? if not, you should. it covers quantifiers early on as they are one of the fundamental features of regexes. a key thing to learn is the

Re: help with another regex

2018-07-17 Thread Lauren C.
yeah you explain that well. thanks. Andy Bach 写道: > But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}' > it expects 1 returned. Well, assuming you mean it shouldn't match as $x starts with a slash and the RE doesn't - you're on the right path.  The

Re: help with another regex

2018-07-17 Thread Lauren C.
Quantifier + : one or more of the previous thing. So "/path/" won't match m{path/\w+} because this regex wants "one or more \w" at that position, which the string doesn't have. If you use m{path/\w*} (note the asterisk) then you're saying "zero or more \w" at that pos

Re: help with another regex

2018-07-17 Thread Andy Bach
> But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}' > it expects 1 returned. Well, assuming you mean it shouldn't match as $x starts with a slash and the RE doesn't - you're on the right path. The reason is, the match goes anywhere, it is "unanchored" so

Re: help with another regex

2018-07-17 Thread Gil Magno
evious thing. Quantifier + : one or more of the previous thing. So "/path/" won't match m{path/\w+} because this regex wants "one or more \w" at that position, which the string doesn't have. If you use m{path/\w*} (note the asterisk) then you're saying "zero or more \w"

Re: help with another regex

2018-07-17 Thread Илья Рассадин
Hi! I think, m{path/(\w+)?/?$} regex can solve your problem. In general, to parse URL, you can use official regex from rfc3986 (see Appendix B for rfc3986) regex is ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? $2 is protocol $4 is host $5 is path $7 is query $9 is fragment

help with another regex

2018-07-17 Thread Lauren C.
Hello, I want to match: /path/ /path/123 /path/abc but /path/?xxx should not be matched. This works: $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' 1 this works too: $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}' But it doesn't work for this case: $ perl -le

Re: Regex for date format

2018-06-29 Thread Mike Martin
Worked perfectly thanks, uri, and same technique works perfectly in postgresql regexp_replace for info On 29 June 2018 at 16:18, Mike Martin wrote: > Thanks > > > On Fri, 29 Jun 2018, 15:48 Uri Guttman, wrote: > >> On 06/29/2018 10:41 AM, Mike Martin wrote: >> >> sorry >> -mm-dd

Re: Regex for date format

2018-06-29 Thread Mike Martin
Thanks On Fri, 29 Jun 2018, 15:48 Uri Guttman, wrote: > On 06/29/2018 10:41 AM, Mike Martin wrote: > > sorry > -mm-dd hh:mm:ss.dd > eg: > 2018-01-01 12-45-10-456789 to > 2018-01-01 12:45:10.456789 > > > > please reply to the list and not to me! > > then why did you want lookbehind? this

Re: Regex for date format

2018-06-29 Thread Uri Guttman
On 06/29/2018 10:41 AM, Mike Martin wrote: sorry -mm-dd hh:mm:ss.dd eg: 2018-01-01 12-45-10-456789 to 2018-01-01 12:45:10.456789 please reply to the list and not to me! then why did you want lookbehind? this is very easy if you just grab the time parts and reassemble them as you

Re: Regex for date format

2018-06-29 Thread Uri Guttman
On 06/29/2018 09:32 AM, Mike Martin wrote: Hi I am trying to convert a string of the format 2018-01-01 16-45-21-654278 to a proper timestamp string so basically I want to replace all -  after the date part i am not sure what you are trying to do. show the after text that you want. a proper

Regex for date format

2018-06-29 Thread Mike Martin
Hi I am trying to convert a string of the format 2018-01-01 16-45-21-654278 to a proper timestamp string so basically I want to replace all - after the date part I am getting a bit stuck, lookbehind doesnt seem to work as it includes the lookbehind on every occurence last attempt is s/(?<=

Re: regex with HEX ascii chars

2018-04-15 Thread Mike Flannigan
Try: binmode(HANDLE) before reading the file. HANDLE is your filehandle. If that doesn't work you might want to supply the text file and a sample script. Mike On 4/12/2018 12:04 PM, beginners-digest-h...@perl.org wrote: I have a text file (created by pdftotext) that I've imported into

Re: regex with HEX ascii chars

2018-04-13 Thread John W. Krahn
On Thu, 2018-04-12 at 17:26 +0100, Gary Stainburn wrote: > I have a text file (created by  pdftotext) that I've imported into my > script. > > It contains ASCII characters 251 for crosses and 252 for ticks. ASCII defines 128 characters so those characters are not ASCII. John -- To

Re: regex with HEX ascii chars

2018-04-13 Thread Gary Stainburn
On Thursday 12 April 2018 19:53:16 Shlomi Fish wrote: > Perhaps see http://perldoc.perl.org/perlunitut.html - you may need to read > the file as binary or iso8859-1 or whatever. Also see Thanks for this Shlomi. I have looked into that before briefly when doing http gets and reading office

Re: regex with HEX ascii chars

2018-04-12 Thread Shlomi Fish
On Thu, 12 Apr 2018 17:26:57 +0100 Gary Stainburn wrote: > I have a text file (created by pdftotext) that I've imported into my script. > > It contains ASCII characters 251 for crosses and 252 for ticks. If I load > the file in gvim and do :as > > it reports

Re: regex with HEX ascii chars

2018-04-12 Thread Andy Bach
> However, when I try to seacch for it using if ($line=~/[\xfb|\xfc]/) { Note, you're mixing the character class " [ab] " with grouping alternative pipe " ( a | b ) " here > or even just if ($line=~/\xfb/) { Dunno, works here: $ perl -e '$line = "hi" . chr 251 . "ho" . chr 252 ; if

regex with HEX ascii chars

2018-04-12 Thread Gary Stainburn
I have a text file (created by pdftotext) that I've imported into my script. It contains ASCII characters 251 for crosses and 252 for ticks. If I load the file in gvim and do :as it reports the characters as 251, Hex 00fb, Octal 373 252, hex 00fc, Octal 374 However, when I try to seacch

Re: interesting regex delimiters

2017-02-25 Thread Andrew Solomon
Thanks Chas., that's interesting! Here's my summary of what I've learnt from this: 1. The regex $foo =~ "\Asome string\Z" is equivalent to $bar = "\Asome string\Z"; # ends up as 'Asome stringB' with a warning $foo =~ /$bar/; i.e evaluate the string first and then sti

Re: interesting regex delimiters

2017-02-24 Thread Chas. Owens
Be careful, it isn't actually a regex; it is a string that will be compiled to a regex. You can see one difference here: #!/usr/bin/perl use v5.20; use warnings; say "string matches:"; for my $s ("foo", "AfooZ") { say "\t$s: ", $s =~ "\Afoo

Re: interesting regex delimiters

2017-02-23 Thread Andrew Solomon
Thanks Uri! On Thu, Feb 23, 2017 at 10:32 PM, Uri Guttman <u...@stemsystems.com> wrote: > On 02/23/2017 05:19 PM, Andrew Solomon wrote: > >> Running Perl 18.2 I was surprised to discover that I can use single and >> double quotes as regex delimiters without the 'm' ope

Re: interesting regex delimiters

2017-02-23 Thread Uri Guttman
On 02/23/2017 05:19 PM, Andrew Solomon wrote: Running Perl 18.2 I was surprised to discover that I can use single and double quotes as regex delimiters without the 'm' operator. For example, instead of writing "/usr/bin/perl" =~ m"/perl" I can just write "

interesting regex delimiters

2017-02-23 Thread Andrew Solomon
Running Perl 18.2 I was surprised to discover that I can use single and double quotes as regex delimiters without the 'm' operator. For example, instead of writing "/usr/bin/perl" =~ m"/perl" I can just write "/usr/bin/perl" =~ "/perl"

Re: Regex for matching files that don't have type extensions

2016-11-05 Thread Shawn H Corey
On Sat, 05 Nov 2016 21:30:12 + Aaron Wells wrote: > True. It could get hairy. Unicode is a pretty vast landscape, and I > think if you only want ASCII word characters to count as things that > could be in a filename, your original [A-Za-z0-9_] is your best bet. > Thanks

Re: Regex for matching files that don't have type extensions

2016-11-05 Thread Octavian Rasnita
From: Aaron Wells True. It could get hairy. Unicode is a pretty vast landscape, and I think if you only want ASCII word characters to count as things that could be in a filename, your original [A-Za-z0-9_] is your best bet. Thanks to the others for their comments. As Ken says: there are

Re: Regex for matching files that don't have type extensions

2016-11-05 Thread X Dungeness
On Sat, Nov 5, 2016 at 10:55 AM, Jovan Trujillo wrote: > Hi Aaron, >In perlre I read that \w > " > > \w[3] Match a "word" character (alphanumeric plus "_", plus > other connector punctuation chars plus > Unicode >

  1   2   3   4   5   6   7   8   9   10   >