I'm kind of interested in seeing what you come up with on your own after spending an hour with perlretut and perlre.

Update: If you're using plain old (non-utf8) strings, the dot character you used has a different code point than if you are using utf8 strings. I'll assume you're dealing with a utf8 string, but you know your dataset better than I do, and can make your own determination in that regard. With that caveat, here's a regex solution for you. ...free of charge today, if you promise to read perlretut, perlrequick, perlre, and perlrecharclass before your next regular expression question. ;)

use strict; use warnings; use utf8; use feature qw( unicode_strings ); binmode STDOUT, ':utf8'; my $string = 'XYZ • Qno-483, sec-9a,ABS • P:(110) 53345345345 • F: (210) 12323123 +1'; printf "Code point for '•': %X\n", ord('•'); if ( $string =~ m/ ^ ( [^\N{U+2022}]+ ) \s\N{U+2022} # Matches XYZ. \s ( [^\N{U+2022}]+ ) \s\N{U+2022} # Matches Qno-483, sec- +9a,ABS \sP:\s* ( [^\N{U+2022}]+ ) \s\N{U+2022} # Matches P:(110) 53345 +345345 \sF:\s* ( [^\N{U+2022}]+ ) \s*$ # Matches F: (210) 1232 +31231 /x ) { print "Match:\n\$1: [$1]\n\$2: [$2]\n\$3: [$3]\n\$4: [$4]\n"; } else { print "Your input string doesn't resemble the one posted to PerlMo +nks.\n"; }

...the output...

Code point for '•': 2022 Match: $1: [XYZ] $2: [Qno-483, sec-9a,ABS] $3: [(110) 53345345345] $4: [(210) 123231231]

Yes, you could have just pasted the 'dot' into your regular expression, or used an input device that provides the character, but then the next person to look at your code will have to go through contortions to figure out what that thing is too.


Dave


In reply to Re: Need assistance in Regular expression by davido
in thread Need assistance in Regular expression by ckj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.