Page 1 of 1

Searching for a string in the text

Posted: Thu Sep 05, 2024 9:12 am
by Natter
Is it possible to use a regular expression to find such a construction in the text:
SPACE+"."+any character+"."

Re: Searching for a string in the text

Posted: Thu Sep 05, 2024 9:20 am
by Antonio Linares
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: Select all | Expand

\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.

Re: Searching for a string in the text

Posted: Thu Sep 05, 2024 9:38 am
by Natter
I understood you correctly ?

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

Re: Searching for a string in the text

Posted: Thu Sep 05, 2024 9:55 am
by Antonio Linares
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

Re: Searching for a string in the text

Posted: Thu Sep 05, 2024 11:41 am
by Natter
it doesn't work

pCompiled := hb_regexComp( "\s\w\.\w\." ) -->***
hb_regex( pCompiled, alltrim(cText) ) --> empty

maybe it's just for the Latin alphabet ?

Re: Searching for a string in the text

Posted: Fri Sep 06, 2024 7:41 am
by Natter
That's how it works:

Code: Select all | Expand

cReg:="\s[А-я][.][А-я][.]"
 res:=HB_ATX(cReg, cText)
 if ! empty(res)
 .................
 endif

Re: Searching for a string in the text

Posted: Fri Sep 06, 2024 9:08 am
by Antonio Linares
great! :-)