Solved

Regex string parse (should be easy) - part 2

Posted on 2010-11-12
8
498 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 500 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 70

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This article will help you understand what HashTables are and how to use them in PowerShell.
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…

786 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