LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-28-2013, 04:42 PM   #1
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Quick Regex Help


Hey All,


A Coworker of mine is trying to learn a little more about regex and asked me for some help when he was working on an exercise on a training site and it looks like the exercise is broken to me and wanted to get another set of eyes to take a look and make sure im not just missing something.

Here is the data set:

Code:
task 	          text 	        capture 	result
capture text 	1280x720 	1280, 720 	✗
capture text 	1920x1600 	1920, 1600 	✗
capture text 	1024x768 	1024, 768 	✗
Here is the regex he was trying to use as the solution:
Code:
(^\d{4}(*\d$))

The exercise leads me to believe that there is an issue with the subgroup setup but it looks right as either part of that regex will match the half he wanted.


Obviously I'm not a regex expert and use it very rarely but this looks like it should work.

Update: Almost 100 views and 0 replies. Does this regex really stump everybody out there? :P

Thanks.

Last edited by Kustom42; 06-28-2013 at 06:44 PM.
 
Old 06-29-2013, 02:16 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by Kustom42 View Post
Update: Almost 100 views and 0 replies. Does this regex really stump everybody out there?
I don't think the regular expression being right or wrong is the issue.

- In which way is this regexp used? Not all commands are able to use regexp's the same way. Is this regexp a part of perl, sed or theoretical?
- The data set you provide doesn't look like an input file, but more like a combined input/output. You might want to provide the an input file and desired output. Or even better: copy/paste the original question that was asked during the training session.
 
Old 06-29-2013, 02:18 AM   #3
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
What exactly are you trying to capture?

^ matches the start of the line, and $ matches the end. The given regex will not match any lines in the given data set.

You seem to be trying to match digits, so if you want to pull out the 'text' column, try this:
Code:
(\d{4}x\d{3,4})
 
Old 06-29-2013, 08:03 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Original Poster
Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
After coming back and reading some of the suggestions here I was able to get the right exp there, the idea was to capture the two sets of digits in sub groups:

Code:
(\d{4})x(\d{3,4})
 
  


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 02:10 AM
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 09:08 PM
need quick regex help with substitution BrianK Programming 3 11-14-2007 02:58 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 06:10 AM
Quick regex problem, can't find solution R00ts Programming 3 05-25-2005 03:55 PM


All times are GMT -5. The time now is 06:38 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