473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Searching through String

Steve G Feb 1, 1:12 pm show options

From: "Steve G" <sgr...@computicle.com> - Find messages by this author

Date: Tue, 01 Feb 2005 13:12:42 -0800
Local: Tues, Feb 1 2005 1:12 pm
Subject: Searching through String
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse

I am using Coldfusion to do some database work. I have a st*ring of
data that is in the format of "name" <email>
I need to have the information between the <> assigned to a *variable,

but the length of the field won't be the same each time.
How can I get this done using JavaScript?
Steve

Jul 23 '05 #1
5 1262
Steve G wrote:
I have a st*ring of data that is in the format of "name" <email>

I need to have the information between the <> assigned to a *variable,


Use a regular expression:

var myString = "\"foo<bar\" <abc@def>";
....
var aSubstrs = myString.match(/"[^"]+"\s+<([^>]+)>/),
myMatch = aSubstrs && aSubstrs[1];

ciao, dhgm

Jul 23 '05 #2
Thanks for the info! I do have a couple of questions:

1) var myString = "\"foo<bar\" <abc@def>";

do I just need this in the code once?

2) I noticed the ...... , is there more that goes between the code
above and the var ASubstrs section?

Thanks!

Steve

Jul 23 '05 #3
Steve G wrote:
1) var myString = "\"foo<bar\" <abc@def>";

do I just need this in the code once?
You don't need this at all. It just supplied a string to test with.
You wrote "I have a string ...". I had none, so I had to get one :-)
2) I noticed the ...... , is there more that goes between the code
above and the var ASubstrs section?


No, I only wanted to indicate that the line above is not actually a
part of the code that implements the substring extraction.

ciao, dhgm
Jul 23 '05 #4
So, if my string looks like:

"Crm-its-datateam Boise" <cr********************@hp.com>
and I wanted to capture just the info in the < > ???

Jul 23 '05 #5
Steve G wrote:
So, if my string looks like:

"Crm-its-datateam Boise" <cr********************@hp.com>
and I wanted to capture just the info in the < > ???


Let's assume you hold your string in a variable named
"myNiceVar" and want to assign the substring to a
variable named "myOtherVar", then use:

var aSubstrs = myNiceVar.match(/"[^"]+"\s+<([^>]+)>/),
myOtherVar = aSubstrs && aSubstrs[1];

A shorter variant is:

var myOtherVar = [].concat(myNiceVar.match(/"[^"]+"\s+<([^>]+)>/))[1];

ciao, dhgm
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
2
by: Roberto Dias | last post by:
Hi all, What to do for searching for more than one string occurrence in the same string (this last are line of a text). I have used getline(), to get the text lines by means of WHILE loop and...
8
by: Gordon Knote | last post by:
Hi can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
8
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way?...
4
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
0
by: richardaz | last post by:
I have been working on a project to search for 250,000 different records in ActiveDirectory. The process takes a long time and I have tried everything to make it faster. Currently using...
4
by: aaronkmar | last post by:
Hello Bytes, I hope this post finds you well on this wonderful Friday! I've been kicking this code around for over a week now and cannot seem to find the correct syntax to handle all of the...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.