Link to home
Start Free TrialLog in
Avatar of n_uthra25
n_uthra25

asked on

tcl+ regexp

Hello,
   I have a question regd regexp in TCL.  

 There is a sring   var = " 1 ABC 2 BCN 3 NNN ooo llll mmm "
  I have to grep [NUMBERS] [ CAPS LETTESR] .
so i'm using  regexp { [0-9]+ [A-z]+ } $var var1
but it greps only 1 ABC . I need to grep all (i.e) 2 BCN 3 NNN
any simple logic or any power usage in regexp.Pls reply

Avatar of leflon
leflon
Flag of Germany image

Hi n_uthra25,

{[0-9]+[ 0-9A-Z]+}
will match any string starting with a number, followed by any combination of blanks, numbers or uppercase letters.
this should match "1 ABC 2 BCN 3 NNN " (ifear it will include the last blank)

leflon
Avatar of n_uthra25
n_uthra25

ASKER

Hello Lefon,
   If you see in $var1 we will find only 1 ABC . But i need 2 BCN 3 NNN ( all the possibilities)  in some variable var2 var3.. so how do to .
  Hope you know regexp always grep first string.

n_uthra25,

ahhh, got it (at last) :)
checking..... (will take some time)

leflon
I don't know what the differences are between TCL's regex engine and Perl's but this is how I'd do it with Perl.

(@vars) = $var =~ /\G\s*(\d+\s+[A-z]+)/g;
This is the test code I used and its output.


#!/usr/bin/perl -w

use Data::Dumper;

$var = " 1 ABC 2 BCN 3 NNN";

(@vars) = $var =~ /\G\s*(\d+\s+[A-z]+)/g;
print Dumper @vars;

----- output -----
$VAR1 = '1 ABC';
$VAR2 = '2 BCN';
$VAR3 = '3 NNN';
Hello FishMonger,
   I would really appreciate if could get it in TCL.

ASKER CERTIFIED SOLUTION
Avatar of leflon
leflon
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
great..Thanks for your reply..