FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Searching for a string in the text
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Searching for a string in the text
Posted: Thu Sep 05, 2024 09:12 AM

Is it possible to use a regular expression to find such a construction in the text:

SPACE+"."+any character+"."

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Searching for a string in the text
Posted: Thu Sep 05, 2024 09:20 AM
Yes, it's possible to use a regular expression to find the construction you described: SPACE + "." + any character + "."

Here's a regular expression that would match this pattern:
Code (fw): Select all Collapse
\s+\.\w\.
Let me break down this regex for you:

1. `\s+`: This matches one or more whitespace characters (including spaces, tabs, and newlines).
2. `\.`: This matches a literal dot (period). The backslash is used to escape the dot, as a dot normally has a special meaning in regex.
3. `\w`: This matches any word character (letters, digits, or underscore).
4. `\.`: Another literal dot.

This regex will find patterns like " .a.", " .B.", " .9.", etc. in your text.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Searching for a string in the text
Posted: Thu Sep 05, 2024 09:38 AM

I understood you correctly ?

HB_ATX([s][.][w][.])

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Searching for a string in the text
Posted: Thu Sep 05, 2024 09:55 AM

LOCAL pCompiled := hb_regexComp( "\s+.\w." )

LOCAL aMatch

LOCAL lRet := .t.

aMatch = hb_regex( pCompiled, alltrim(cText) )

if Empty( aMatch )

    lRet := .f.

end

return lRet
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Searching for a string in the text
Posted: Thu Sep 05, 2024 11:41 AM

it doesn't work

pCompiled := hb_regexComp( "\s\w.\w." ) -->***

hb_regex( pCompiled, alltrim(cText) ) --> empty

maybe it's just for the Latin alphabet ?

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Searching for a string in the text
Posted: Fri Sep 06, 2024 07:41 AM
That's how it works:
Code (fw): Select all Collapse
cReg:="\s[А-я][.][А-я][.]"
 res:=HB_ATX(cReg, cText)
 if ! empty(res)
 .................
 endif
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Searching for a string in the text
Posted: Fri Sep 06, 2024 09:08 AM
great! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion