Solved

Need a Bit more change in the extraction of name from email address

Posted on 2010-11-09
11
278 Views
Last Modified: 2012-05-10
<CFSet variables.extracted =REMatch("""[^""]+""" , """The randhawa"" <myselfrandhawa@yahoo.com>")>
<CFDump var= "#variables.extracted#" label ="Email Address">


Currently it is showing as:

"The randhawa"

i want it to be as:

The randhawa

removing the quotes, please guide
0
Comment
  • 6
  • 3
  • 2
11 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 84 total points
ID: 34096935
Try this:
<CFSet variables.extracted =REMatch("(?<="")[^""]+(?="")" , """The randhawa"" <myselfrandhawa@yahoo.com>")>
<CFDump var= "#variables.extracted#" label ="Email Address">

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 34097511
Lookbehind is not supported in CF.

You may get by with the following, but it will fail if you have any text with a quote before it. For example, the following:

    "This is awesome!!"; "The randhawa" <myselfrandhawa@yahoo.com>

would return

    This is awesome!!
<CFSet variables.extracted=REMatch("[^""]+(?="")", """The randhawa"" <myselfrandhawa@yahoo.com>") />
<CFDump var=#variables.extracted# label="Email Address" />

Open in new window

0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34097537
Thanks, kaufmed, for the correction! I worship your regexly knowledge! ;-)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34097592
I'm always disappointed whenever I find a new language/editor that doesn't fully support lookaround  :)
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 34097617
Maybe two regex operations would be better:
<CFSet variables.extracted=REMatch("""[^""]+", """The randhawa"" <myselfrandhawa@yahoo.com>") />
<CFSet variables.extracted=REReplace(variables.extracted[1],"""","") />
<CFDump var=#variables.extracted# label="Email Address" />

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34097806
>> I'm always disappointed whenever I find a new language/editor that doesn't
>> fully support lookaround  :)

Yeah,  that's one failing in the basic regex functionality. But you could easily use the underlying java, which IIRC does support it ;-)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34097826
@_agx_

I haven't gotten quite that far in my CF experiments yet, but true nonetheless  : )
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34097833
Since it all compiles to java anyways, why is there such a difference between the CF regex and the Java?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34097850
Backward compatibility maybe? (CF wasn't always java based).  But that's a total guess ;-)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34097859
>>  ... CF wasn't always java based...

Ahh. Did not know that.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34097891
Yeah, it's been java based for a while now. But back in dinosaur days it was written in C++ ;-)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question