Pattern Matching

Posted on 1998-09-10
Medium Priority
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.
Question by:IsleOfView

Accepted Solution

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


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


Author Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

587 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