Solved

Regex string parse (should be easy) - part 2

Posted on 2010-11-12
8
499 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
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…

808 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