Xojo Conferences
XDCMay2019MiamiUSA

RegEx and variables (Real Studio getting started Mailinglist archive)

Back to the thread list
Previous thread: Re: gettingstarted Digest, Vol 11, Issue 3
Next thread: Getting Tab Panel Tab Index


RB Database   -   tom.russell transport.alstom.com
  RegEx and variables   -   SB D
    RE: RegEx and variables   -   POIDINGER, Michael [JJRAU]
     Re: RegEx and variables   -   Stuart Malin
    RE: RegEx and variables   -   POIDINGER, Michael [JJRAU]
     Re: RegEx and variables   -   Stuart Malin

RegEx and variables
Date: 02.02.05 23:05 (Wed, 02 Feb 2005 17:05:27 -0500)
From: SB D
Using - Realbasic 5.5 Professional Version Windows OS

I would like to use the RegEx method to search for a string that changes
constantly.
Here is my code:

dim rg as Regex
dim myMatch as RegExMatch
yyy = str(mlasty) //mlasty is an integer that changes constantly

rg.SearchPattern = yyy //**here is the problem**
myMatch=rg.search(picpositionY)

What is the proper way to refer to yyy?

thanks sbd

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

RE: RegEx and variables
Date: 02.02.05 23:20 (Thu, 3 Feb 2005 09:20:32 +1100 )
From: POIDINGER, Michael [JJRAU]



> -----Original Message-----
> From: <email address removed>
> [mailto:<email address removed>] On
> Behalf Of SB D
> Sent: Thursday, February 03, 2005 9:05 AM
> To: <email address removed>
> Subject: RegEx and variables
>
> Using - Realbasic 5.5 Professional Version Windows OS
>
> I would like to use the RegEx method to search for a string
> that changes constantly.
> Here is my code:
>
> dim rg as Regex
> dim myMatch as RegExMatch
> yyy = str(mlasty) //mlasty is an integer that changes constantly
>
> rg.SearchPattern = yyy //**here is the problem**
> myMatch=rg.search(picpositionY)
>

dim rg as new Regex

But given what you are searching for is not really a pattern, just use the
str functions, they will be much faster than regex

dim pos as integer
pos = instr(picpositionY, yyy) //returns 0 of not found, 1-based array
index otherwise

Mike
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: RegEx and variables
Date: 03.02.05 02:05 (Wed, 2 Feb 2005 17:05:30 -0800)
From: Stuart Malin

On Feb 2, 2005, at 2:20 PM, POIDINGER, Michael [JJRAU] wrote:
>
> dim rg as new Regex
>
> But given what you are searching for is not really a pattern, just use
> the
> str functions, they will be much faster than regex
>
> dim pos as integer
> pos = instr(picpositionY, yyy) //returns 0 of not found, 1-based array
> index otherwise

Mike makes a very good point.

However, let's say you need to be sure that the integer you are
searching for is not contained within another

Example, say yyy is 101 and the string you are searching has " 21013"
in it, then instr will give you a match on the 101 within 21013.

So, use a Regex with a pattern that enforces white space or boundaries:

dim pattern as string
pattern = "[^\s]" + yyy + "[$\s]"

Use the Regex normally.

What this pattern does is to say:

look for the string yyy
preceded by: either the start of the string, or some white space
followed by: either the end of the string, or some white space

HTH,
Stuart

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

RE: RegEx and variables
Date: 03.02.05 02:17 (Thu, 3 Feb 2005 12:17:27 +1100 )
From: POIDINGER, Michael [JJRAU]
> On Feb 2, 2005, at 2:20 PM, POIDINGER, Michael [JJRAU] wrote:
> >
> > dim rg as new Regex
> >
> > But given what you are searching for is not really a
> pattern, just use
> > the str functions, they will be much faster than regex
> >
> > dim pos as integer
> > pos = instr(picpositionY, yyy) //returns 0 of not found, 1-based
> > array index otherwise
>
> Mike makes a very good point.
>
> However, let's say you need to be sure that the integer you
> are searching for is not contained within another

Stuart makes a good point :)

> dim pattern as string
> pattern = "[^\s]" + yyy + "[$\s]"
>

Actually, ^ in a [] means not. Much better would maybe be (my regex is
rusty)

pattern = "^|\s" + yyy + "\s|$"

> Use the Regex normally.
>
> What this pattern does is to say:
>
> look for the string yyy
> preceded by: either the start of the string, or some white space
> followed by: either the end of the string, or some white space
>
> HTH,
> Stuart
>

if the string was to be embedded (not the entire string being searched, lose
the ^ and $
pattern = "\s?" + yyy + "\s?"
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: RegEx and variables
Date: 04.02.05 16:22 (Fri, 4 Feb 2005 10:22:13 -0500)
From: Stuart Malin

On Feb 2, 2005, at 8:17 PM, POIDINGER, Michael [JJRAU] wrote:

>> On Feb 2, 2005, at 2:20 PM, POIDINGER, Michael [JJRAU] wrote:
>>>
>>> dim rg as new Regex
>>>
>>> But given what you are searching for is not really a
>> pattern, just use
>>> the str functions, they will be much faster than regex
>>>
>>> dim pos as integer
>>> pos = instr(picpositionY, yyy) //returns 0 of not found, 1-based
>>> array index otherwise
>>
>> Mike makes a very good point.
>>
>> However, let's say you need to be sure that the integer you
>> are searching for is not contained within another
>
> Stuart makes a good point :)
>
>> dim pattern as string
>> pattern = "[^\s]" + yyy + "[$\s]"
>>
> Actually, ^ in a [] means not. Much better would maybe be (my regex is
> rusty)
>
> pattern = "^|\s" + yyy + "\s|$"

Oops, was I ever brain dead when I wrote that. But, I did so to avoid
parenthesizing the ^|\s
I am not sure, but I think that in order to use the vertical bar "or"
operand, the entities need
to be contained in parentheses, as in:

pattern = "(^|\s)" + yyy + "(\s|$)"

which means that when the pattern is matched, one must look at sub
strings to find the actual match.
Though, in this case that may be moot, because all one wants to know is
IF the string yyy is found.
>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>