Need a regular expression expert

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Need a regular expression expert

    I need a regular expression expert on this one.... I got this expression from
    regexlib.com and am puzzled on how to convert it to work in CF. Anyone have
    any Ideas?



    (?:(?<protocol> http(?:s?)|ftp)(?:\:\/\/))
    (?:(?<usrpwd>\w+\:\w+)(?:\@))?
    (?<domain>[^/\r\n\:]+)?
    (?<port>\:\d+)?
    (?<path>(?:\/.*)*\/)?
    (?<filename>.*?\.(?<ext>\w{2,4}))?
    (?<qrystr>\??(?:\w+\=[^\#]+)(?:\&?\w+\=\w+)*)*
    (?<bkmrk>\#.*)?

    I would like to be able to create a match structure from the named elements in
    this regex.....

    mylink = structnew();
    mylink.protocol = match
    mylink.path = match ..... etc.

    wiseduck Guest

  2. Similar Questions and Discussions

    1. Regular expression help
      Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract...
    2. help on regular expression
      Hi, I need some help on regular expression... i have following in variable $total_count $total_count = "##I USBP 000001 10:38:09(000)...
    3. regular expression - help
      can anyone translate this into plain english? preg_match_all("/(\w+)+/U", $text, $words);
    4. Regular Expression HELP!
      I'm stripping out the attributes in <TD> tags...but I want to strip out everything BUT the COLSPAN attribute. The following strips out all...
    5. Regular Expression Expert Please.
      Chinadian <chinadian@ma.2y.net> wrote: ^ ^ ^ ^ useless backslashes should not be there No it isn't. The character class matches any...
  3. #2

    Default Re: Need a regular expression expert

    How about something like this:

    <cfcomponent name="REMatcher">
    <cfset This.EXPRS = StructNew () />
    <cfset This.EXPRS.PROTOCOL = "(?:(?<protocol> http(?:s?)|ftp)(?:\:\/\/))"
    />
    <cfset This.EXPRS.USRPWD = "(?:(?<usrpwd>\w+\:\w+)(?:\@))?" />
    <cfset This.EXPRS.DOMAIN = "(?<domain>[^/\r\n\:]+)?" />
    <cfset This.EXPRS.PORT = "(?<port>\:\d+)?" />
    <cfset This.EXPRS.PATH = "(?<path>(?:\/.*)*\/)?" />
    <cfset This.EXPRS.FILENAME = "(?<filename>.*?\.(?<ext>\w{2,4}))?" />
    <cfset This.EXPRS.QRYSTR =
    "(?<qrystr>\??(?:\w+\=[^\#]+)(?:\&?\w+\=\w+)*)*" />
    <cfset This.EXPRS.BKMRK = "(?<bkmrk>\#.*)?" />

    <cffunction name="Matches" returntype="boolean" access="public">
    <cfargument name="Arg" type="string" required="yes" />
    <cfargument name="Expr" type="string" required="yes" />
    <cfset var result = REFind (Arguments.Expr, Arguments.Arg, "False") />
    <cfreturn result />
    </cffunction>
    </cfcomponent>


    <!--- Example. --->
    <cfset str = "stringgoeshere" />
    <cfset matcher = CreateObject ("Component", "REMatcher") />
    <cfset mylink = StructNew () />
    <cfset mylink.protocol = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.PROTOCOL) />
    <cfset mylink.usrpwd = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.USRPWD) />
    <cfset mylink.domain = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.DOMAIN) />
    <cfset mylink.port = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.PORT) />
    <cfset mylink.path = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.PATH) />
    <cfset mylink.filename = matcher,matches (Arg = str, Expr =
    REMatcher.EXPRS.FILENAME) />
    <cfset mylink.qrystr = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.QRYSTR) />
    <cfset mylink bkmrk = matcher.matches (Arg = str, Expr =
    REMatcher.EXPRS.BKMRK) />


    Darryl


    On Sat, 23 Jul 2005 05:04:18 -0600, wiseduck
    <webforumsuser@macromedia.com> wrote:
    > I need a regular expression expert on this one.... I got this
    > expression from
    > regexlib.com and am puzzled on how to convert it to work in CF. Anyone
    > have
    > any Ideas?
    >
    >
    >
    > (?:(?<protocol> http(?:s?)|ftp)(?:\:\/\/))
    > (?:(?<usrpwd>\w+\:\w+)(?:\@))?
    > (?<domain>[^/\r\n\:]+)?
    > (?<port>\:\d+)?
    > (?<path>(?:\/.*)*\/)?
    > (?<filename>.*?\.(?<ext>\w{2,4}))?
    > (?<qrystr>\??(?:\w+\=[^\#]+)(?:\&?\w+\=\w+)*)*
    > (?<bkmrk>\#.*)?
    >
    > I would like to be able to create a match structure from the named
    > elements in
    > this regex.....
    >
    > mylink = structnew();
    > mylink.protocol = match
    > mylink.path = match ..... etc.
    >


    --
    Using Opera's revolutionary e-mail client: [url]http://www.opera.com/mail/[/url]
    Darryl A. J. Staflund Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139