Solved

Regular Expressions

Posted on 2013-05-24
6
225 Views
Last Modified: 2013-05-24
I have a simple request:

I have something like this:

Lastname^Firstname^^^

sometimes

Lastname^Firstname^MI^^

What I need is a regular expression like ([^.]*).[^.]*.[^.]* that would show me just the Lastname as a result, then just the first name, then just the middle initial.

The example I pasted will do it if it is like Lastname.Firstname.MI, but I do not have any idea how to work with carrot symbols since those are already being used in the expression.
0
Comment
Question by:weklica
  • 2
  • 2
  • 2
6 Comments
 

Author Comment

by:weklica
ID: 39194820
I thought maybe this, but that isn't it.  

([^^]*)^[^^]*^[^^]*
0
 

Assisted Solution

by:waltzing_wombat
waltzing_wombat earned 150 total points
ID: 39194979
If these are PERL regular expressions, the ^ symbol at the start of a [] set of characters refers to a set of characters that don't include what's in the set. e.g. [^0-9] matches everything except the digits 0 to 9.

It's semantics is different from ^ which refer to start of expression. I'm not really sure what you need, but since escaping things never hurt, try this:

([^\^]*)^([^\^]*)^([^\^]*)

in PERL matches to
lastname=$1
firstname=$2
mi=$3

If you're so sure '^' never occurs in the name, alternatively you can do
@parts = s/\^//;
$lastname = shift @parts;
$firstname= shift @parts;
$mi = shift @parts;
0
 
LVL 84

Expert Comment

by:ozo
ID: 39194983
([^^]*)
should be is sufficient for just Lastname
([^^]*)\^([^^]*)\^([^^]*)
should get Last, then First, then middle
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Expert Comment

by:waltzing_wombat
ID: 39194999
Yup, my mistake, ozo's right, you gotta escape the carat outside the matching sets too.
0
 
LVL 84

Accepted Solution

by:
ozo earned 350 total points
ID: 39195019
not knowing who's regular expressions you are using, or how escapes work in your system, this should work without escapes:
([^^]*).([^^]*).([^^]*)
0
 

Author Closing Comment

by:weklica
ID: 39195060
Thanks Much!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

816 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

8 Experts available now in Live!

Get 1:1 Help Now