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

  • SEARCH
  • Home
  • 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 8745067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:56:45+00:00 2026-06-13T11:56:45+00:00

I need regex help to create a delphi function to replace the HyperString ParseWord

  • 0

I need regex help to create a delphi function to replace the HyperString ParseWord function in Rad Studio XE2. HyperString was a very useful string library that never made the jump to Unicode. I’ve got it mostly working but it doesn’t honor quote delimiters at all. I need it to be an exact match for the function described below:

function ParseWord(const Source,Table:String;var Index:Integer):String;

Sequential, left to right token parsing using a table of single
character delimiters. Delimiters within quoted strings are ignored.
Quote delimiters are not allowed in Table.

Index is a pointer (initialize to ‘1’ for first word) updated by the
function to point to next word. To retrieve the next word, simply
call the function again using the prior returned Index value.

Note: If Length(Resultant) = 0, no additional words are available.
Delimiters within quoted strings are ignored. (my emphasis)

This is what I have so far:

function ParseWord( const Source, Table: String; var Index: Integer):string;
var
  RE : TRegEx;
  match : TMatch;
  Table2,
  chars : string;
begin
  if index = length(Source) then
  begin
    result:= '';
    exit;
  end;

  // escape the special characters and wrap in a Group
  Table2 :='['+TRegEx.Escape(Table, false)+']';
  RE := TRegEx.create(Table2);
  match := RE.Match(Source,Index);
  if match.success then
  begin
    result := copy( Source, Index, match.Index - Index);
    Index := match.Index+match.Length;
  end
  else
  begin
    result := copy(Source, Index, length(Source)-Index+1);
    Index := length(Source);
  end;
end;

  while ( Length(result)= 0) and (Index<length(Source)) do
  begin
    Inc(Index);
    result := ParseWord(Source,Table, Index);
  end;

cheers and thanks.

  • 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-06-13T11:56:46+00:00Added an answer on June 13, 2026 at 11:56 am

    In my original code I was looking for the delimiter and taking everything up to that as my next match, but that concept didn’t carry over when looking for something within quotes. @Stephan’s suggestion of negating the search eventually lead me to something that works. An additional complication that I never mentioned earlier is that HyperStr can use anything as a quoting character. The default is double quote but you can change it with a function call.

    In my solution I’ve explicitly hardcoded the QuoteChar as double quote, which suits my own purposes, but it would be trivial to make QuoteChar a global and set it within another function. I’ve also successfully tested it with single quote (ascii 39), which would be the tricky one in Delphi.

    function ParseWord( const Source, Table: String; var Index: Integer):string;
    var
      RE : TRegEx;
      match : TMatch;
      Table2: string;
      Source2 : string;
      QuoteChar : string;
    begin
      if index = length(Source) then
      begin
        result:= '';
        exit;
      end;
    
      // escape the special characters and wrap in a Group
      QuoteChar := #39;
      Table2 :='[^'+TRegEx.Escape(Table, false)+QuoteChar+']*|'+QuoteChar+'.*?'+QuoteChar ;
      Source2 := copy(Source, Index, length(Source)-index+1);
      match := TRegEx.Match(Source2,Table2);
      if match.success then
      begin
        result := copy( Source2, match.index, match.length);
        Index := Index + match.Index + match.Length-1;
      end
      else
      begin
        result := copy(Source, Index, length(Source)-Index+1);
        Index := length(Source);
      end;
      while ( Length(result)= 0) and (Index<length(Source)) do
      begin
        Inc(Index);
        result := ParseWord(Source,Table, Index);
      end;
    
    end;
    

    This solution doesn’t strip the quote chars from around quoted strings, but I can’t tell from my own existing code if it should or not, and I can’t test using Hyperstr. Maybe someone else knows?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help writing a regex function that converts HTML string to a valid
Im totally new to regex. I need your help. What is the regex function
Can someone help me create this regex. I need it to check to see
I need help to create a regex (for JavaScript .match and PHP preg_match) that
I have the following string: $/Mycollection/Branches/Dev/New/php/MySite/src/MySite/somefolder/src/sad.php I need to create regex pattern and take
Can someone help me here? I need to create a regex that will meet
I need to create a regex to match this format: B001169875 Can someone help
I need a regex expert to help out on this one. Examples I've found
I need help on regex or preg_match because I am not that experienced yet
I need some help using regex in java. Im trying to achieve 2 different

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.