Solved

Regular Expressions

Posted on 2013-05-24
6
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 

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

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

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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

631 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