Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Unexpected RegEx results
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mirco Wahab, post: 4834332"] I was under the impression your data would not only consist of /one/ record but rather a good sequence of them, so the regex would need to climb down (find) the records and spit out the correct matches, # Example: four record thing with "offending" structure ==> my $morestuff=' ALWAYSPRESENT:0008:0:PRESENT PRESENT MAYBEPRESENT Some Text 1:0000:0:More Text 1 Some Text 2:0000:0:More Text 2 Text22 text22 text22 Some Text 3:0000:0:More Text 3 Text3 text3 Text33 text33 text33 '; # and so on ... # Now, the regex should identify them # and step along ==> my $rg = qr/ \s* ^([^:]+) : \d+ : \d+ : ([^\n]+)?\n (?: ^([^:\n]+?) \n)? (?: ^([^:\n]+?) (?:\n|$) )?/mx; # This was the "shortest" thing I could find so # far (within your constraints), the record- # walking would be within a while ==> while( $morestuff =~ /$rg/g ) { printf "%s %s\n\t%s\n\t%s\n", $1||'undef', $2||'undef', $3||'undef', $4||'undef'; } # ... which would give the correct matches. Maybe I misunderstood your problem somehow, but I found the task quite nice and interesting (maybe somebody would write down a really simple regular expression for that - (not me, sleeping time now in this country ;-). Regards Mirco [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Unexpected RegEx results
Top