Searching for a string in the text

Searching for a string in the text

Postby Natter » Thu Sep 05, 2024 9:12 am

Is it possible to use a regular expression to find such a construction in the text:
SPACE+"."+any character+"."
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Searching for a string in the text

Postby Antonio Linares » Thu Sep 05, 2024 9: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: Select all  Expand view
\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
User avatar
Antonio Linares
Site Admin
 
Posts: 42065
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Searching for a string in the text

Postby Natter » Thu Sep 05, 2024 9:38 am

I understood you correctly ?

HB_ATX([s][.][w][.])
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Searching for a string in the text

Postby Antonio Linares » Thu Sep 05, 2024 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42065
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Searching for a string in the text

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

Re: Searching for a string in the text

Postby Natter » Fri Sep 06, 2024 7:41 am

That's how it works:
Code: Select all  Expand view
cReg:="\s[А-я][.][А-я][.]"
 res:=HB_ATX(cReg, cText)
 if ! empty(res)
 .................
 endif
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Searching for a string in the text

Postby Antonio Linares » Fri Sep 06, 2024 9:08 am

great! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42065
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 45 guests