Regular Expressions

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

I have something like this:




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.
Question by:weklica
  • 2
  • 2
  • 2

Author Comment

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


Assisted Solution

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

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;
LVL 84

Expert Comment

ID: 39194983
should be is sufficient for just Lastname
should get Last, then First, then middle
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

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

Accepted Solution

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:

Author Closing Comment

ID: 39195060
Thanks Much!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Suggested Solutions

Title # Comments Views Activity
looking for unix program to search some keywords in side EAR WAR and JAR files 10 100
shell script 2 38
Using an inventory file in a script 7 36
AWK: Pythagoras script 6 23
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 …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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