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

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?

Thanks,

Jerry



Sat, 08 Dec 2012 23:14:45 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string

Quote:

>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?

>Thanks,

>Jerry

I would think long and hard before doing this.

use strict;
use warnings;

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

$pat =~ s/(X+)/'(' . '.'x length($1) . ')'/eg;
$pat =~ tr/#/./;
print join '', $data =~ /$pat/s;

-sln



Sun, 09 Dec 2012 01:58:51 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string

Quote:

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

That depends entirely on what meaning you assign to
the "X" and "#" characters in your pattern language.

What meaning do you assign to the "X" and "#" characters in your
pattern language?

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.



Sun, 09 Dec 2012 04:36:44 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string

Quote:

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

> That depends entirely on what meaning you assign to
> the "X" and "#" characters in your pattern language.

> What meaning do you assign to the "X" and "#" characters in your
> pattern language?

> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
> The above message is a Usenet post.
> I don't recall having given anyone permission to use it on a Web site.

Tad,

I want to keep # data and disregard X data/position in a string that
is being read from a serial port.



Sun, 09 Dec 2012 21:53:37 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string

Quote:



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

>> That depends entirely on what meaning you assign to
>> the "X" and "#" characters in your pattern language.

>> What meaning do you assign to the "X" and "#" characters in your
>> pattern language?

>> --
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
>> The above message is a Usenet post.
>> I don't recall having given anyone permission to use it on a Web site.

You are not supposed to quote .sigs.

Please don't do that.

Have you seen the posting guidelines that are posted here frequently?

Quote:
> Tad,

> I want to keep # data and disregard X data/position in a string that
> is being read from a serial port.

You said:

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

that does not match up with your new rules, as you should get ".7" by
these new rules...

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.



Sun, 09 Dec 2012 22:37:16 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string
[please don't quote .sigs]


Quote:


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

> > That depends entirely on what meaning you assign to
> > the "X" and "#" characters in your pattern language.

> > What meaning do you assign to the "X" and "#" characters in your
> > pattern language?

> I want to keep # data and disregard X data/position in a string that
> is being read from a serial port.

    my $pat  = "XXXXX##";
    my $data = "1234567";

    $pat =~ tr/X#/xa/;

    my $input = join "", unpack $pat, $data;

Ben



Sun, 09 Dec 2012 22:41:22 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string

Quote:

>I want to keep # data and disregard X data/position in a string that
>is being read from a serial port.

As someone said tr/X#/xa/ and unpack would be the way to go.
However, without an anchor or other frame reference, this will
do you absolutely no good whatsoever.

-sln



Mon, 10 Dec 2012 01:10:04 GMT  
 How to use Regex to breakdown a pattern and use the pattern to break down a string
Tad,

I inverted the pattern, SORRY!  It should be "#######XX"

Regards

Jerry



Tue, 11 Dec 2012 18:46:10 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Question of using OR in the pattern matching

2. Using a string for a regexp pattern

3. How to grep using an array of patterns?

4. Using $*, but pattern doesn't match

5. Pattern match time out error using Net::Telnet

6. Pattern match time out error using Net::Telnet

7. Pattern matching using variable ...

8. How can ??-pattern matching be used?

9. Can you pattern match using an array?

10. using search pattern

11. Using a variable in pattern matching operator

12. using variables in patterns

 

 
Powered by phpBB® Forum Software