Author |
Message |
Chris #1 / 8
|
 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 |
|
 |
s.. #2 / 8
|
 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 |
|
 |
Tad McClella #3 / 8
|
 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 |
|
 |
Chris #4 / 8
|
 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 |
|
 |
Tad McClella #5 / 8
|
 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 |
|
 |
Ben Morro #6 / 8
|
 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 |
|
 |
s.. #7 / 8
|
 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 |
|
 |
Chris #8 / 8
|
 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 |
|
|