Monks, I have a regex question for you. I have this string of text...
Posted by mad max beyond eggdome on September 04, 2003
Using this regex...
source =~ /^posted by((\w|\s)+)\son\s/i;
I can get "mad max beyond eggdome", which is what I need to pull out. I need to grab everything between "posted by" and the word "on". My problem with that regex is there could be other characters other than \w or \s in between posted by and (space)on(space) and the word "on" could also be a possibility.

So, I tried this...
source =~ /^posted by([^\son\s]+)\son\s/i;
However, a character class is just that, a character. It's not a group. I can't figure out how to group the characters with a NOT.

I tried this also...
source =~ /^posted by([^(\son\s)]+)\son\s/i;
Which I thought would group the (space)on(space) in the character class, but that did not work either. How do you group the characters to say "not group of characters"? I want to say...

Start at the beginning, look for the string "posted by" and then gather all characters that are not (space)on(space), until I find the string (space)on(space). I don't think I'm going in the correct direction.

Thanks for any help, it is greatly appreciated.

In reply to Grouped characters inside character class. by the_0ne

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.