?
Solved

Regex string parse (should be easy) - part 2

Posted on 2010-11-12
8
Medium Priority
?
508 Views
Last Modified: 2012-05-10
I 4 separate expressions to extract the following from a single line:
- initials
- winning score
- losing score
- winning team

Here's the text:

KR    3 to 1 for VAN
MT    4-1 VAN
CH    ??? no pick?
MC  3 1 OTT
TS    4 - 2   VAN
JS    ???
RA    3 -2 vancouver
BJ    5- 3 VAN
RV    4 - 2 ottowa
CA    ???
TD    ???


(orig question: http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_26611607.html)
0
Comment
Question by:Gitcho
  • 4
  • 2
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34125480
Does it need to be separate? You could write one and use capture groups. Continuing from your last response:
([a-zA-Z]{2,3})\s*(\d+)[ -/A-Za-z]+(\d+)([ A-Za-z]+)

Capture group 1: Initials
Capture group 2: Score 1
Capture group 3: Score 2
Capture group 4: Team Name

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34125516
Using the "-match" operation, you are given access to the variable "$matches", which is an array. You can extract the capture groups by indexing this array as $matches[1] => first capture group, etc. Here is a screenshot.
untitled.PNG
0
 
LVL 5

Author Comment

by:Gitcho
ID: 34125713
yeah - i see where you're goin with that ... the last capture needs to be just the 3 letter team name tho
0
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34125798
Right, but if you'll recall our last discussion, that depends on how you expect your data to come in. phr0ze's pattern merely captured a series of alphas and spaces. We can modify the pattern to capture the right-most "word", but if you have something like "for VAN is awesome" you'll receive "awesome" as the result.
0
 
LVL 5

Author Comment

by:Gitcho
ID: 34129273
The team will be the last word on the line
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 34132438
Try the following:

([a-zA-Z]{2,3})\s*(\d+)[ -/A-Za-z]+(\d+)[ A-Za-z]*([A-Za-z]+)$
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34497712
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Loops Section Overview

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question