House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Regex Q

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

Regex Q

Responses inline: Barney Boisvert 05/12/2004 01:33 PM
Oops--- Dick Applebaum 05/12/2004 01:16 PM
ok, lemme try and break this down: Charlie Griefer 05/12/2004 01:15 PM
<cfset email = ReReplaceNocase(email, ".*<([^>]*)>.?", "\1")/> Dick Applebaum 05/12/2004 01:12 PM
This'll do it: Barney Boisvert 05/12/2004 01:05 PM
On another forum, a user asked how to turn this string: Charlie Griefer 05/12/2004 01:00 PM

05/12/2004 01:33 PM
Author: Barney Boisvert Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162988 Responses inline: > ok, lemme try and break this down: > > ^[^<]  anything at the beginning of the string that is NOT an opening > bracket (which would take care of the FirstName LastName and > any spaces) > > +< an opening bracket Not quite right; should be like this: ^[^<]+ one or more characters at the beginnging that ar enot openeing brackets.  That should be a * not a + as well, to handle the case that the first char is the "<". < an opening bracket > ([^>]+)  this is where I start to get lost.  I know the [^>] > is anything > that is not a closing bracket...but not sure where the + > comes in inside of > the parentheses. Working from inside out, [^>] means anything except a closing bracket, the + means one or more such characters, and the parentheses mean "store the enclosed value for backreferencing".   > >.*$ a closing bracket, and anything that might follow it > (such as trailing > spaces). Bingo! > Also, I know the \1 is a 'backreference'...just not exactly > sure what that > means.  If you could clarify the ([^>]+) and the \1 I'd be eternally > grateful :) When we stored the value using parantheses it gets stored with a number reference.  Since it's the first such value (you can have multiple), it gets to be "1".  We can reference that value anywhere later in the regular expression, or in the replace string by prepending it with a backslash. Here's some more examples: Rereplace("catdog", "cat(.*)", "\1\1") => dogdog Rereplace("'dog'", "(['""])(.*)\1", "\1\2\2\1") => 'dogdog' Rereplace("""dog""", "(['""])(.*)\1", "\1\2\2\1") => "dogdog" Rereplace("'dog""", "(['""])(.*)\1", "\1\2\2\1") => 'dog" In the first case, we double whatever is after 'cat'.  In numbers 2-4 we use the same RE and search stirng for all three.  It searches for a single or double quote and stores it, then 'anything' and stores it, then a MATCHING quote (using the backreference).  We replace it with the same quote, and the 'anything' twice, and then the quote again.  #2 uses single quotes, #3 uses double quotes, and #4 uses mixed quotes, which DOESN'T work, so the replace doesn't happen.   Cheers, barneyb
05/12/2004 01:16 PM
Author: Dick Applebaum Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162983 Oops--- <cfset email = ReReplaceNocase(email, ".*<([^>]*)>.*", "\1")/> is better On May 12, 2004, at 10:10 AM, Dick Applebaum wrote: ----- Excess quoted text cut - see Original Post for more -----
05/12/2004 01:15 PM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162982 ok, lemme try and break this down: ^[^<]  anything at the beginning of the string that is NOT an opening bracket (which would take care of the FirstName LastName and any spaces) +< an opening bracket ([^>]+)  this is where I start to get lost.  I know the [^>] is anything that is not a closing bracket...but not sure where the + comes in inside of the parentheses. >.*$ a closing bracket, and anything that might follow it (such as trailing spaces). Also, I know the \1 is a 'backreference'...just not exactly sure what that means.  If you could clarify the ([^>]+) and the \1 I'd be eternally grateful :) Charlie > This'll do it: > > Rereplace(email, "^[^<]+<([^>]+)>.*$", "\1", "one") > > I threw the extra ".*" in there at the end because the possibility of having > trailing spaces is always there, and we can clean it up at the same time, so ----- Excess quoted text cut - see Original Post for more -----
05/12/2004 01:12 PM
Author: Dick Applebaum Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162981 <cfset email = ReReplaceNocase(email, ".*<([^>]*)>.?", "\1")/> HTH Dick On May 12, 2004, at 9:58 AM, Charlie Griefer wrote: ----- Excess quoted text cut - see Original Post for more -----
05/12/2004 01:05 PM
Author: Barney Boisvert Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162980 This'll do it: Rereplace(email, "^[^<]+<([^>]+)>.*$", "\1", "one") I threw the extra ".*" in there at the end because the possibility of having trailing spaces is always there, and we can clean it up at the same time, so why not? Cheers, barneyb ----- Excess quoted text cut - see Original Post for more -----
05/12/2004 01:00 PM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32463#162978 On another forum, a user asked how to turn this string: FirstName LastName <somebody@somewhere.com> into this string: somebody@somewhere.com I was able to come up with: <cfset email = reReplace(left(email, len(email)-1), '(^.*<)', '', 'all')> I feel a little cheesy using the left() function to remove that last bracket, as I'm sure there must have been a way within the same regex. I tried a variety of things, such as adding .$ and even the literal > to the expression above, but I assume that means it was looking for that expression as an expression itself.  But there has to be a way to say, replace (this exp) AND (that exp)?  or would it just be a case of nesting reReplace() functions? Charlie -still trying to get a handle on regex
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     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     

Designer, Developer and mobile workflow conference