Solved

Pattern Matching

Posted on 1998-09-10
2
223 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

749 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