Regular Expressions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leon

    #1

    Regular Expressions

    Hi!

    Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5 reference??

    Eg. pattern - "(a-z)*(0-9)*"

    $1 - some text
    $2 - some number

    Thanx for any help!

    Leon.


  • Lyle Fairfield

    #2
    Re: Regular Expressions

    "Leon" <etre@op.pl> wrote in news:bqj4e0$c4f $1@news.onet.pl :
    [color=blue]
    > Hi!
    >
    > Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5
    > reference??
    >
    > Eg. pattern - "(a-z)*(0-9)*"
    >
    > $1 - some text
    > $2 - some number
    >
    > Thanx for any help!
    >
    > Leon.[/color]

    An Example (the news client has inserted line breaks):

    Option Explicit

    ' assumes VBScript is installed

    Dim RE As Object

    Sub TestAplphaOnly( )
    Dim StringToBeMaske d As String ' string to be masked
    Dim MaskPattern As String ' mask note this can be formatted
    ' as a regular expression pattern
    Dim Globally As Boolean ' global search
    Dim IgnoreCase As Boolean ' ignore case

    StringToBeMaske d = "L1Y9L3E7"
    MaskPattern = "[^A-Z]" ' Alpha Only
    ' that is,
    ' remove all characters except those from A to
    Z
    Globally = True
    IgnoreCase = True
    InitializeRegEx p MaskPattern, Globally, IgnoreCase

    SetMask StringToBeMaske d

    ' to test only
    ' remove for actual use

    MsgBox StringToBeMaske d

    ReleaseRegExp
    End Sub

    Public Sub InitializeRegEx p( _
    ByRef MaskPattern As String, _
    Optional ByRef Globally As Boolean = True, _
    Optional ByRef IgnoreCase As Boolean = True)
    Set RE = CreateObject("V BScript.RegExp" ) 'late binding ... Dev would
    squirm With RE
    .Global = Globally
    .IgnoreCase = IgnoreCase
    .Pattern = MaskPattern
    End With
    End Sub

    Public Sub ReleaseRegExp()
    Set RE = Nothing
    End Sub

    Public Sub SetMask(ByRef StringToBeMaske d As String)
    StringToBeMaske d = RE.Replace(Stri ngToBeMasked, "")
    End Sub

    --
    Lyle
    (for e-mail refer to http://ffdba.com/contacts.htm)

    Comment

    • Leon

      #3
      Re: Regular Expressions

      U¿ytkownik "Lyle Fairfield" <MissingAddress @Invalid.Com> napisa³ w
      wiadomo¶ci news:Xns9445B6B 1A819CFFDBA@130 .133.1.4...[color=blue]
      > "Leon" <etre@op.pl> wrote in news:bqj4e0$c4f $1@news.onet.pl :
      >[color=green]
      > > Hi!
      > >
      > > Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5
      > > reference??
      > >
      > > Eg. pattern - "(a-z)*(0-9)*"
      > >
      > > $1 - some text
      > > $2 - some number
      > >
      > > Thanx for any help!
      > >
      > > Leon.[/color]
      >
      > An Example (the news client has inserted line breaks):
      >
      > Option Explicit
      >
      > ' assumes VBScript is installed
      >
      > Dim RE As Object
      >
      > Sub TestAplphaOnly( )
      > Public Sub InitializeRegEx p( _
      > Public Sub ReleaseRegExp()
      > Public Sub SetMask(ByRef StringToBeMaske d As String)
      >
      > Lyle
      > (for e-mail refer to http://ffdba.com/contacts.htm)[/color]

      Hello again!

      I saw similar code before, but it is not what I'm looking for
      May be I didn't make my self as I wanted to. :)

      I want to have access to variables which contains
      submatches of my regural expression
      (in PERL I used $1..$9 etc.)

      Eg. pattern - "(([a-z])*([0-9])*)"

      $1 - some text
      $2 - some number
      $3 - tome text and some number

      On MSDN site I saw some thing like RegExp.$1 but it dosen't work

      http://msdn.microsoft.com/library/de...us/script56/ht
      ml/reconbackrefere nces.asp

      Regards Leon!



      Comment

      • TC

        #4
        Re: Regular Expressions

        Wouldn't you get more help on this in a visual basic scripting group? Your
        question is nothing to do with Access, as such.

        HTH,
        TC


        "Leon" <etre@op.pl> wrote in message news:bqj4e0$c4f $1@news.onet.pl ...[color=blue]
        > Hi!
        >
        > Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5 reference??
        >
        > Eg. pattern - "(a-z)*(0-9)*"
        >
        > $1 - some text
        > $2 - some number
        >
        > Thanx for any help!
        >
        > Leon.
        >
        >[/color]


        Comment

        • Leon

          #5
          Re: Regular Expressions

          Dear TC!

          My questoin has many to do with access, as you can see
          I was asking about VBA (in context of Access), not VBS!

          I know the solution for VBS, it's on MSDN site but
          it won't work in my case.

          So I decieded to ask question on this group ;)

          Regards and thanx 4 your advice!

          Leon.


          U¿ytkownik "TC" <a@b.c.d> napisa³ w wiadomo¶ci
          news:1070418498 .845519@teuthos ...[color=blue]
          > Wouldn't you get more help on this in a visual basic scripting group? Your
          > question is nothing to do with Access, as such.
          >
          > HTH,
          > TC
          >
          >
          > "Leon" <etre@op.pl> wrote in message news:bqj4e0$c4f $1@news.onet.pl ...[color=green]
          > > Hi!
          > >
          > > Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5[/color][/color]
          reference??[color=blue][color=green]
          > >
          > > Eg. pattern - "(a-z)*(0-9)*"
          > >
          > > $1 - some text
          > > $2 - some number
          > >
          > > Thanx for any help!
          > >
          > > Leon.
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • TC

            #6
            Re: Regular Expressions

            But you are asking about how to use the methods & properties of "VBS Reg
            Expr 5.5". There is nothing in any VBA help, that will evevr help you with
            that. You need >VBS< help to help you with that, no?

            Cheers,
            TC


            "Leon" <etre@op.pl> wrote in message news:bqk70h$4cv $1@news.onet.pl ...[color=blue]
            > Dear TC!
            >
            > My questoin has many to do with access, as you can see
            > I was asking about VBA (in context of Access), not VBS!
            >
            > I know the solution for VBS, it's on MSDN site but
            > it won't work in my case.
            >
            > So I decieded to ask question on this group ;)
            >
            > Regards and thanx 4 your advice!
            >
            > Leon.
            >
            >
            > U¿ytkownik "TC" <a@b.c.d> napisa³ w wiadomo¶ci
            > news:1070418498 .845519@teuthos ...[color=green]
            > > Wouldn't you get more help on this in a visual basic scripting group?[/color][/color]
            Your[color=blue][color=green]
            > > question is nothing to do with Access, as such.
            > >
            > > HTH,
            > > TC
            > >
            > >
            > > "Leon" <etre@op.pl> wrote in message news:bqj4e0$c4f $1@news.onet.pl ...[color=darkred]
            > > > Hi!
            > > >
            > > > Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5[/color][/color]
            > reference??[color=green][color=darkred]
            > > >
            > > > Eg. pattern - "(a-z)*(0-9)*"
            > > >
            > > > $1 - some text
            > > > $2 - some number
            > > >
            > > > Thanx for any help!
            > > >
            > > > Leon.
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...