Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Regular Expressions

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
weklica
Asked:
weklica
  • 2
  • 2
  • 2
2 Solutions
 
weklicaAuthor Commented:
I thought maybe this, but that isn't it.  

([^^]*)^[^^]*^[^^]*
0
 
waltzing_wombatCommented:
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
 
ozoCommented:
([^^]*)
should be is sufficient for just Lastname
([^^]*)\^([^^]*)\^([^^]*)
should get Last, then First, then middle
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
waltzing_wombatCommented:
Yup, my mistake, ozo's right, you gotta escape the carat outside the matching sets too.
0
 
ozoCommented:
not knowing who's regular expressions you are using, or how escapes work in your system, this should work without escapes:
([^^]*).([^^]*).([^^]*)
0
 
weklicaAuthor Commented:
Thanks Much!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now