Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regex string parse (should be easy) - part 2

Posted on 2010-11-12
8
Medium Priority
?
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

609 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