Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use Regex to breakdown a pattern and use the pattern to break down a string

9 views
Skip to first unread message

ChrisC

unread,
Jun 23, 2010, 4:22:21 PM6/23/10
to
I will get a user defined patten "XXXXX##', "##XXXXX##",
"##XX##XX##",
"XXX" etc. How to break down this string pattern using Regex and
apply it to data;

Pattern "XXXXXXXX##" to break out string "00000078.7\r\n" to get
"00000078.7";


Pattern ""##XX##XX##" to break out string "LB78KL.7l\n" to get
"78.7";


etc......


Or what is the best way to do this?

This is a start in Perl:

my $data = "LB78KL.7l\n";
my $pat = "##XX##XX##";

$pat =~ s/(X+)/'(' . '.'x length($1) . ')'/eg; // how to do this in
csharp
$pat =~ tr/#/./; // how to do
this in csharp
print join '', $data =~ /$pat/s;

Thanks,


Jerry


0 new messages