LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2018, 03:29 AM   #1
myre75
Member
 
Registered: Nov 2013
Location: Lyon, France
Distribution: Slackware MLED 14.2 64 Bits
Posts: 30

Rep: Reputation: Disabled
REGEX : detecting repetitive caracters


Hi all,

I need to detect, in Perl, a [0-9a-zA-Z_] where first repetetive characters will be find.

Ex :
abcd => NOK
aabcd => OK (aa)
abcdyyyyyy => OK (yyyyyy

thank you,

Regards,
 
Old 01-10-2018, 03:33 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,744

Rep: Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473Reputation: 2473
Like you said, you need this.

So what effort have you made ?.
 
1 members found this post helpful.
Old 01-10-2018, 09:36 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,664

Rep: Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538
Quote:
Originally Posted by myre75 View Post
I need to detect, in Perl, a [0-9a-zA-Z_] where first repetetive characters will be find.

Ex :
abcd => NOK
aabcd => OK (aa)
abcdyyyyyy => OK (yyyyyy
You said you need to detect where the first repetitive characters will be found... yet your example simply indicates "found" or "not found." Please rethink and restate the problem.

Daniel B. Martin

.
 
Old 01-10-2018, 09:50 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,016

Rep: Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276
you ought to check how regexp groups work and how can you specify repetition of a group.
 
Old 01-10-2018, 02:50 PM   #5
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 797

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Back-reference is the right term here. Repetition is misleading.
A repetition of the previous search pattern character:
Code:
[0-9a-zA-Z_]{2}
A back-reference needs a group, and it refers to what actually has been matched within the group.
Code:
([0-9a-zA-Z_])\1
Note: in perl the \1 remains available as $1 outside the regexp.
Code:
perl -lne '/([0-9a-zA-Z_])\1/ and print $1'
 
1 members found this post helpful.
Old 01-11-2018, 01:26 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,016

Rep: Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276Reputation: 3276
obviously, repetition was not used as a keyword, but was originally used by the OP (and was repeated). And also I did not want to give a full solution - because it is against the rules of LQ.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Keyboard special caracters gabsik Linux - General 3 12-18-2008 02:54 AM
Wine with strange caracters Guilherme Linux - Software 4 05-22-2007 07:01 PM
Quanta isn't show right caracters stormrider_may Linux - Software 2 05-12-2006 01:38 PM
vfat suport for foreign caracters PunkPT Linux - Software 1 05-05-2004 01:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration