Solved

Pattern Matching

Posted on 1998-09-10
2
231 Views
Last Modified: 2010-03-05
What is the correct syntax for performing the following functions?

a.)  I have a variable ($MyVariable) with a string as its value. The string would be something like this:  "sometext||some-other-text".  I want to return just the text to the LEFT of the "||" (or any delimiter).

b.)Taking that one step further, if $MyVariable = "sometext||some-other-text::even-more-text".  I need functions to extract each portion of the string.
0
Comment
Question by:IsleOfView
[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
2 Comments
 
LVL 1

Accepted Solution

by:
stormerider earned 30 total points
ID: 1204796
a.) Hmmm, Pier Xanthony?

b.)

($a, $b, $c) = split(/|/, $MyVariable);
This is assuming you meant there were three variable fields, else:
($a, $b) = split(/||/, $MyVariable);

0
 

Author Comment

by:IsleOfView
ID: 1204797
Good answer--that worked great, except that you need to escape the |'s with "\".  Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

717 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