Given that in your examples the operands are in the character class [a-z] you could split on the boundary between operand and operator using look-behinds and look-aheads. You split either at a point preceded by the character class [a-z] and followed by the negated character class [^a-z] or vice versa, like this

use strict; use warnings; print map {qq{$_->[0] -- $_->[1] -- $_->[2]\n}} map { [ split m {(?x) (?: (?<=[a-z])(?=[^a-z]) | (?<=[^a-z])(?=[a-z]) ) } ] } map {chomp; $_} <DATA>; __END__ a=b a!=b a<b a<=b a>b a>=b

which gives this output

a -- = -- b a -- != -- b a -- < -- b a -- <= -- b a -- > -- b a -- >= -- b

Given a more complex set of operators you would probably be better off taking grinder's approach of setting up a regular expression that matches and captures any operator. As complexity increases a parser solution becomes more appropriate.

I hope this is of use.

Cheers,

JohnGG


In reply to Re: Regular Expressions by johngg
in thread Regular Expressions by Anonymous Monk

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.