Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
wiseduck #1
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
-
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... -
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)... -
regular expression - help
can anyone translate this into plain english? preg_match_all("/(\w+)+/U", $text, $words); -
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... -
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... -
Darryl A. J. Staflund #2
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



Reply With Quote

