Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 782017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:19:13+00:00 2026-05-14T20:19:13+00:00

I’m working on a fairly specialized search engine implementation in Perl, it searches (by

  • 0

I’m working on a fairly specialized search engine implementation in Perl, it searches (by regex) documents for specifically delimited (a subset of :punct:) strings from a text file. I’m doing the usual search engine indexing tricks, but there’s a problem.

Some of the search regex patterns include, by necessity, delimiters used in the file. “Ok, I think to myself, “word proximity, then… easy” …and that side of the equation is straight forward enough.

The trick is that because the search patterns are regular expressions, I haven’t easily determined the specific words that I should go looking for in the indexed data (think “split” if we’re talking about more ordinary strings).

Trivial example, “square[\s-]*dance” would match directly on “squaredance” but a proximity match on “square dance” and “square-dance” (since ‘-‘ is a delimiter). I need to know, based on the regex, to look for “square” and “dance” separately, but nearby each other.

I’m game for the challenge, but I’d rather use established code. My gut tells me that it’ll be an internal hook to the regex engine, but I don’t know of anything like that. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:19:13+00:00Added an answer on May 14, 2026 at 8:19 pm

    The re pragma can produce the information you seem to be interested in.

    use strict;
    use warnings;
    use re qw(Debug DUMP);
    
    my $re = qr/square[\s-]*dance/;
    
    'Let\'s go to the square dance!' =~ $re;
    

    Output:

    Compiling REx "square[\s-]*dance"
    Final program:
       1: EXACT <square> (4)
       4: STAR (17)
       5:   ANYOF[\11\12\14\15 \-][+utf8::IsSpacePerl] (0)
      17: EXACT <dance> (20)
      20: END (0)
    anchored "square" at 0 floating "dance" at 6..2147483647 (checking anchored) minlen 11 
    Freeing REx: "square[\s-]*dance"
    

    Unfortunately, there doesn’t appear to be a programmatic hook to get this information. You’d have to intercept the output on STDERR and parse it. Rough proof-of-concept:

    sub build_regexp {
        my $string = shift;
        my $dump;
    
        # save off STDERR and redirect to scalar
        open my $stderr, '>&', STDERR or die "Can't dup STDERR";
        close STDERR;
        open STDERR, '>', \$dump or die;
    
        # Compile regexp, capturing DUMP output in $dump
        my $re = do {
            use re qw(Debug DUMP);
            qr/$string/;
        };
    
        # Restore STDERR
        close STDERR;
        open STDERR, '>&', $stderr or die "Can't restore STDERR";
    
        # Parse DUMP output
        my @atoms = grep { /EXACT/ } split("\n", $dump);
    
        return $re, @atoms;
    }
    

    Use it this way:

    my ($re, @atoms) = build_regexp('square[\s-]*dance');
    

    $re contains the pattern, @atoms contains a lists of the literal portions of the pattern. In this case, that’s

       1: EXACT <square> (4)
      17: EXACT <dance> (20)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.