Solved

Regex string parse (should be easy) - part 2

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

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 74

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 74

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 74

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
A procedure for exporting installed hotfix details of remote computers using 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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now