+ Reply to Thread
Results 1 to 10 of 10

Passing a RegEx to a function

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Passing a RegEx to a function

    Hi,

    This function is not working as intended. I believe that the issue lies with the argument I'm calling the function with. Other than a string, I don't know how to pass the argument. Any ideas ?

    Please Login or Register  to view this content.
    Returns "Product : \d{10} not found"

    Thanks,
    amphi
    Last edited by amphinomos; 12-30-2014 at 11:21 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Passing a RegEx to a function

    What string or pattern are you trying to find?

    Obviously, one would call it something like this:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: Passing a RegEx to a function

    Thanks Kenneth.
    I'm trying to find 10 digits (only one instance) in the string. When running your example, I get a blank msgbox.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Passing a RegEx to a function

    You mean 10 digits of what? If you mean a specific string, just send the string.

    The function as you set will return a string. Even when the string is found, nothing is returned as you did not tell the function to send some string.

    Did you mean 10 digits after a specific string?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: Passing a RegEx to a function

    My string is formatted as such "This will be called Product : 1234567890" I'd like to return "Product : 1234567890". Not sure why my function is not returning anything ?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Passing a RegEx to a function

    Try removing 'Product : ' from the expression.

    By the way, isn't the function meant to return something?
    If posting code please use code tags, see here.

  7. #7
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: Passing a RegEx to a function

    Yes it should. Eventually I would like to return the 10 matched digits. I probably need to work on the MatchCollection property to return the string as the regex execute method doesn't directly return a string. http://www.regular-expressions.info/vbscript.html

    Thanks anyways for your help.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Passing a RegEx to a function

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Passing a RegEx to a function

    This will return the match if there is one, if there isn't it'll return an empty string.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: Passing a RegEx to a function

    Thank you both

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] RegEx replace in range with lagre data set as sub/function?
    By knutfh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2013, 03:33 AM
  2. passing arrays to function
    By MrReds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2012, 07:33 PM
  3. Return text with regex find function
    By jrussell in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-07-2010, 08:28 AM
  4. [SOLVED] Passing a row to a function
    By dch3 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-31-2006, 07:38 AM
  5. [SOLVED] passing a value to another function
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2005, 04:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1