Matches options

Kalan

Member
Hi,

I need to find way to compare the string to check the criteria ‘523.....45’ i.e string starting with ‘523’, then any 5 characters and ends with ‘45’. Here I can think about matches function But matches '523*45' can have any number of characters, we cant restrict that to certain digits. Is there any other alternative straight forward function available in progress other than manually writing the logic to work out this please?

Thanks.
 

Cringer

ProgressTalk.com Moderator
Staff member
The . (dot) signifies a single character IIRC, so you could match "523.....45" I think. What platform are you on? If Windows you can leverage the regex functionality in the MS .Net Framework for free.
 

RealHeavyDude

Well-Known Member
With matches you can just specify a pattern like "*myString*". You can't define how many characters are required to match an asteriks ( wild card ).

Can the "*45" appear anywhere in the string?
Do the strings have a fixed length?

Heavy Regards, RealHeavyDude.
 

Stefan

Well-Known Member
Hi,

I need to find way to compare the string to check the criteria ‘523.....45’ i.e string starting with ‘523’, then any 5 characters and ends with ‘45’. Here I can think about matches function But matches '523*45' can have any number of characters, we cant restrict that to certain digits. Is there any other alternative straight forward function available in progress other than manually writing the logic to work out this please?

Thanks.

You do not have access to the manual? Select 'MATCHES' press F1...

pattern
A character expression that you want to match with the string. This can include a constant, field name, variable name, or expression whose value is a character.
The pattern can contain wildcard characters: a period (.) in a particular position indicates that any single character is acceptable in that position; an asterisk (*) indicates that any group of characters is acceptable, including a null group of characters.
 

Kalan

Member
@ RHD Can the "*45" appear anywhere in the string?
Do the strings have a fixed length?
"*45" appears end of the string. Its like range that numbers starts with ‘523 and ends with 45. For ex. 5234567845. We store this value in character field, so its fixed length.

@ Cringer The . (dot) signifies a single character IIRC, so you could match "523.....45" I think.
As per my understanding matches clause does not allow .(dot) to define the number of characters to match with. Could you pls clarify this single character IIRC.

@ Stefan: My apologies, I do have access to manual(F1) but I dont think using matches I am able to achieve this. Hence I would like to know is there any other functions/clause available to signify .(dot) while matching the string?

Thanks for your replies.
 

Stefan

Well-Known Member
What do you mean with 'any characters'? Since this is exactly what dot matches and it does not seem to meet your needs. Do you maybe mean 'any digit - ie 0 thru 9'?

Please add some explicit cases of what you think should and should not meet your criteria.
 

Stefan

Well-Known Member
@Stefan - Since its character data type, For ex. ... - Three dots can be any 3 digits integer like 4 5 6 OR Letters like a b c.

So you mean digit?

523aaaaa45 should not match
5230000045 should match

If that is the case you can use matches to get the most likely ones and then check they are digits with trim.

Code:
myfield MATCHES "523.....45" AND TRIM( myfield, "0123456789" ) = ""
 

Stefan

Well-Known Member
I need to find way to compare the string to check the criteria ‘523.....45’ i.e string starting with ‘523’, then any 5 characters and ends with ‘45’.

A digit is a character.
A space is a character.
A letter is a character.
 

Cringer

ProgressTalk.com Moderator
Staff member
@Cringer - OE 10.2B Windows platform.
You should definitely look at using the .Net Framework then. It has full support for regular expressions in there and it's not that hard to leverage it in a Windows environment. Pretty certain it works ok in 10.2B. I don't have source at the moment, but as soon as the presentations from the PUG Challenge are out I can point you in the direction of a very useful session I went to.
 

TomBascom

Curmudgeon
The problem with using regular expressions to solve a problem is that you then have two problems to solve...

I think I would avoid a REGEX and instead code something along these lines:

(Just for illustration purposes I will assume that "customer.name" is the field that we are searching.)

Code:
for each customer no-lock where name begins "523":   /* BEGINS allows an indexed lookup to be used, this will make the query a whole lot faster */

  if length( customer.name ) <> 10 then     /* the target is "523" + 5 characters + "45" -- length must equal 10 characters... */
    next.

  if substring( customer.name, 9 ) <> "45" then     /* the last 2 characters must be "45" */
    next.
  
   /* whatever */

end.
 

Kalan

Member
Just to update, I have managed to acheive this using below logic,
Code:
ASSIGN <SearchResult> = FALSE.
IF CAN-FIND(FIRST <TableName> WHERE <TableName>.Comp = iComp
AND <TableName>.<SourceFieldName> = <SearchInputString>) THEN
  ASSIGN <SearchResult> = TRUE.
ELSE IF CAN-FIND(FIRST <TableName> WHERE <TableName>.Comp = iComp
AND <SearchInputString> MATCHES <TableName>.<SourceFieldName>) THEN /* Check the case where where *<String> OR <String>* */
  ASSIGN <SearchResult> = TRUE.
ELSE DO:
  EBLK:
  FOR EACH <TableName> NO-LOCK WHERE <TableName>.Comp = iComp
  AND LENGTH(<TableName>.<SourceFieldName>) = LENGTH(<SearchInputString>):
    DCHECK:
    REPEAT iCCCount = 1 TO LENGTH(<SearchInputString>):
      IF SUBSTRING(<SearchInputString>, iCCCount, 1) = "." OR
      SUBSTRING(<TableName>.<SourceFieldName>, iCCCount, 1) = "." OR
      SUBSTRING(<SearchInputString>, iCCCount, 1) = SUBSTRING(<TableName>.       <SourceFieldName>, iCCCount, 1) THEN
          ASSIGN <SearchResult> = TRUE.
       ELSE
          ASSIGN <SearchResult> = FALSE.

        IF <SearchResult> = FALSE THEN
            LEAVE DCHECK.
      END. /* DCHECK */

      IF <SearchResult> = TRUE THEN
         LEAVE EBLK.
END. /* EBLK */

END. /* IF CAN-FIND(FIRST <TableName> WHERE <TableName>.Comp = iComp ELSE */
 
Last edited by a moderator:

Cringer

ProgressTalk.com Moderator
Staff member
Have made a bash at formatting the code better but it's not perfect. Better than it was :)
 

TomBascom

Curmudgeon
Impossible to read without CODE tags and all of the important bits are left out anyway but even so it is apparent that the code is either solving a different problem than was originally described or it is an overly complex and baroque approach best suited for shops where job security is enhanced by creating unmaintainable gibberish that will need to be constantly attended to.
 
Top