Results 1 to 2 of 2

Thread: Regular Expression questions

  1. #1

    Thread Starter
    Member leazfe's Avatar
    Join Date
    Mar 2004
    Location
    Spain
    Posts
    43

    Regular Expression questions

    I have three doubt:

    1. In the next expresion: (?<desc>\w+) , how can i save in "desc" all the word fitting the expresion, for example with the next source: "Hallo ich bin ich" it should keep the hole string but it only has "Hallo".

    2. How can i do an if statment with regular expresion. I have a string that could have a number or not, in the event of no number exist the string "" is asigned and i get always a cast exception, i have tried something like this:
    (?(\d2)(?<status>\d2)|0)

    3. How can i count the number of time that has appeared an expresion ?


    Thanks,
    Álvaro

  2. #2
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694

    Re: Regular Expression questions

    Originally posted by leazfe
    I have three doubt:

    1. In the next expresion: (?<desc>\w+) , how can i save in "desc" all the word fitting the expresion, for example with the next source: "Hallo ich bin ich" it should keep the hole string but it only has "Hallo".

    Simply do not use (? .... ) because using (? will not return the match.

    use (<desc>\w+) instead.

    You find it then either in the match on in the submatches collection.

    2. How can i do an if st
    atment with regular expresion. I have a string that could have a number or not, in the event of no number exist the string "" is asigned and i get always a cast exception, i have tried something like this:
    (?(\d2)(?<status>\d2)|0)


    3. How can i count the number of time that has appeared an expresion ?

    dim matchcol as matchcollection
    set matchcol=regexp.execute(mytext)
    number of matches = matchcol.count i think

    Thanks,
    Álvaro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width