Solved

Regular Expressions

Posted on 2013-05-24
6
221 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

16 Experts available now in Live!

Get 1:1 Help Now