Search by format

Post Reply
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Search by format

Post by Natter »

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 "??/??/????")
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Search by format

Post by nageswaragunupudi »

Use RegEx
Example:

Code: Select all | Expand

   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
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Search by format

Post by Natter »

Great! Thanks !
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Search by format

Post by Natter »

how to include regular expression unicode characters (for example: « » ) ?
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Search by format

Post by nageswaragunupudi »

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
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: Search by format

Post by Natter »

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)
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Search by format

Post by nageswaragunupudi »

Code: Select all | Expand

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
Post Reply