FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Search by format
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Search by format

Posted: Wed Aug 02, 2023 06:41 AM
Hi,

Is it possible to search in the text by format ?
For example, there is a date in the text in the form of dd/mm/yyyy.
I need to find this fragment and determine that it is exactly the date (a la Excel - mask search "??/??/????")
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Search by format

Posted: Wed Aug 02, 2023 08:37 AM
Use RegEx
Example:
Code (fw): Select all Collapse
   cRegExDate := "[0-3][0-9][-|/|.][0-1][0-9][-|/|.][1-2][0-9][0-9][0-9]"
   ? HB_ATX( cRegExDate, "His date of birth is 20/10/1986, What is his age?" )
   // result "20/10/1986"
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Re: Search by format

Posted: Wed Aug 02, 2023 08:49 AM

Great! Thanks !

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Re: Search by format

Posted: Wed Aug 02, 2023 09:46 AM
how to include regular expression unicode characters (for example: « » ) ?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Search by format

Posted: Wed Aug 02, 2023 03:43 PM

Are you programming for East Asian languages?

If you are confined to English and West European languages, all characters other than accented characters are represented by a single byte (and the same byte) both in ANSI and UTF8.

So, normal RegEx expressions should work with UTF8 text also, if you are not programming for Asian languages

Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Re: Search by format

Posted: Wed Aug 02, 2023 03:55 PM
That's not how I asked the question. :(
I am interested in a regular expression for a date of this format «06» April 2023 (months may be different)
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Search by format

Posted: Thu Aug 03, 2023 03:44 PM
Code (fw): Select all Collapse
local cRegEx := "[«][0-3][0-9][»]"
? hb_atx( cRegEx , "test this «23». working" )
Result : "«23»"
Note: These are not Unicode characters.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion