LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Quick Regex Help (https://www.linuxquestions.org/questions/linux-newbie-8/quick-regex-help-4175467751/)

Kustom42 06-28-2013 03:42 PM

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.

druuna 06-29-2013 01:16 AM

Quote:

Originally Posted by Kustom42 (Post 4980435)
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.

AlucardZero 06-29-2013 01:18 AM

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})

Kustom42 06-29-2013 07:03 PM

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})


All times are GMT -5. The time now is 03:15 PM.