in reply to Re: Need a Regular Expression that tests for words in different order and captures the values found.
in thread Need a Regular Expression that tests for words in different order and captures the values found.

Great thanks, I was able to get it to work(sortof) with this line:
$line =~ /^(?=.*fred\s+(\w+))(?=.*barney\s+(\w+))(?=.*joe\s+(\w+))/ ; $company = join '_', $1, $2, $3, 'inc';
  • Comment on Re^2: Need a Regular Expression that tests for words in different order and captures the values found.
  • Download Code

Replies are listed 'Best First'.
Re^3: Need a Regular Expression that tests for words in different order and captures the values found.
by AnomalousMonk (Archbishop) on Jan 15, 2010 at 17:19 UTC
    ... I was able to get it to work(sortof) ...

    This implies the solution does not entirely fulfill your needs. In what way does it fall short?

      it goes above and beyond in filling my needs
      the "sortof" was meant that, the script that I'm bashing out isn't
      actually looking for flintstones or rubbles, but parsing settings
      from a config file, where the names of the settings arent in a
      consistent order
      e.g. I want "one two three" but most of the time all three are there
      just in a random order
      There was an article in The Perl Journal(I have the Oreilly book)
      by Jeffrey Friedl that mentioned the
      /^(?=.*one)(?=.*two)/
      solution, but I didnt know how(or that you could) capture, inside
      non consuming parenthesis.
Re^3: Need a Regular Expression that tests for words in different order and captures the values found.
by furry_marmot (Pilgrim) on Jan 15, 2010 at 15:42 UTC

    Heh, I just replied with this very solution (see below). Put a question mark after each closing parenthesis and it should work.

    $line =~ /^(?=.*fred\s+(\w+))?(?=.*barney\s+(\w+))?(?=.*joe\s+(\w+))?/ + ; $company = join '_', $1, $2, $3, 'inc';
    --marmot