Solved

Regular Expressions

Posted on 2013-05-24
6
223 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
incorrect file reading in bash 7 81
Bash Script-Trigger email when server reboots 11 68
Changing Audit Policies through scripting 5 56
IE 11 + long running scripts 3 29
This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

21 Experts available now in Live!

Get 1:1 Help Now