Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

REGULAR EXPRESSIONS - easy for a master

REGULAR EXPRESSIONS - easy for a master

REGULAR EXPRESSIONS - easy for a master

I need to get the two numbers from this line immediatley followed by ns (ie the 5.678 & 7.908)

DAMN "I_DONT_KNOW_PERL" WELL = 23 nS AS ¦ 5.678ns   ¦   7.908ns    ¦     7


(sorry if this is a bit simplistic - I've only been doing perl for 3 days)

Gordon Bell

RE: REGULAR EXPRESSIONS - easy for a master

$string = 'stuff ¦ 12.34ns ¦ 34.56ns';

# explain match - \d* - matches zero or more digits
#               - \.{0,1} - matches zero or one dot
#               - \d* - matches zero or more digits
#               - ns - obviously matches 'ns'
#               - the 'g' - match as many times as possible
while ($string =~ /\d*\.{0,1}\d*ns/g)
    print "$&\n";
# $& catches matched patterns

RE: REGULAR EXPRESSIONS - easy for a master

Take a look at the split function.  Say your string is in the variable $My_String...

@Items = split("¦", $My_String);

@Items is an array that will now hold each field from $My_String as a seperate array item.  The "¦" in the split command says to use the ¦ character as a field delimiter.

Remembering that arrays in perl are indexed from 0, you can now refer to the "ns" fields as $Items[1] and $Items[2].

Hope this helps.

RE: REGULAR EXPRESSIONS - easy for a master

How do I make the string $My_String - it is in a complete file of data of various sorts.

Gordon Bell

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close