Searching for a string in the text

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

Searching for a string in the text

Post by Natter »

Is it possible to use a regular expression to find such a construction in the text:
SPACE+"."+any character+"."
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Searching for a string in the text

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: Searching for a string in the text

Post by Natter »

I understood you correctly ?

HB_ATX([s][.][w][.])
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Searching for a string in the text

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: Searching for a string in the text

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

Re: Searching for a string in the text

Post by Natter »

That's how it works:

Code: Select all | Expand

cReg:="\s[А-я][.][А-я][.]"
 res:=HB_ATX(cReg, cText)
 if ! empty(res)
 .................
 endif
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Searching for a string in the text

Post by Antonio Linares »

great! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply