f



regular expression to parse {"hello", "hello world", "1hello-2*hello"}

Hi,I was trying to use Java's regular expression to parse the followingstring:{"hello", "hello world",         "1hello-2*hello"}I'd like to extract the words inside the quotation marks as follows:hellohello world1hello-2*helloI've tried different ways to write the expression but didn't work thisout. Can anyone help?Thanks a lot.Roy
0
Roy
1/6/2008 11:46:51 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

6 Replies
754 Views

Similar Articles

[PageSpeed] 40

Roy wrote:> I was trying to use Java's regular expression to parse the following> string:> hello> hello world> 1hello-2*helloWhy do you asking us to do your homework?Goto: http://java.sun.com/j2se/1.5.0/docs/api/ , class Patternand remember about double backslash (\\).--   Pozdrawiam,  J.W.
0
Jacek
1/6/2008 3:00:19 PM
Jacek Wojciechowski wrote:> Why do you asking us to do your homework?> Hey Roy, here's a free tip: It is very likely to get responses like this when making requests of the form "Please solve my problem!" without showing and explaining *what you* have tried already and what your exact problem with your approach is.regards,/W
0
Wildemar
1/6/2008 3:59:40 PM
On Jan 6, 7:59 am, Wildemar Wildenburger<lasses_w...@klapptsowieso.net> wrote:> Jacek Wojciechowski wrote:> > Why do you asking us to do your homework?>> Hey Roy, here's a free tip: It is very likely to get responses like this> when making requests of the form "Please solve my problem!" without> showing and explaining *what you* have tried already and what your exact> problem with your approach is.>> regards,> /WHi Jacek,Thank you for the tip.  Actually, this is not my homework. I juststarted learning regular expression last night and came up with thisproblem. I've tried many ways to parse this string but haven'tsucceeded yet.The problem that bugs me is the spaces inside the quotation marks andthe spaces outside of them. I don't know how to write an expression todistinguish them. Of course I believe I can find other ways to parsethe string without using any regular expressions. But I am justcurious whether a simple expression can do the job.Here are what I've tried:Enter your regex: [^{},"]+Enter input string to search: {"hello", "hello world","1hello-2*hello"}I found the text "hello" starting at index 2 and ending at index 7.I found the text " " starting at index 9 and ending at index 10.I found the text "hello world" starting at index 11 and ending atindex 22.I found the text "         " starting at index 24 and ending at index33.I found the text "1hello-2*hello" starting at index 34 and ending atindex 48.I found the text " " starting at index 50 and ending at index 51.Enter your regex: [^{},"\s+]+Enter input string to search: {"hello", "hello world","1hello-2*hello"}I found the text "hello" starting at index 2 and ending at index 7.I found the text "hello" starting at index 11 and ending at index 16.I found the text "world" starting at index 17 and ending at index 22.I found the text "1hello-2*hello" starting at index 34 and ending atindex 48.
0
Roy
1/6/2008 4:58:19 PM
Roy wrote:> Hi,> > I was trying to use Java's regular expression to parse the following> string:> > {"hello", "hello world",         "1hello-2*hello"}> > I'd like to extract the words inside the quotation marks as follows:> > hello> hello world> 1hello-2*hello> > I've tried different ways to write the expression but didn't work this> out. Can anyone help?> > Thanks a lot.> RoyThe simplest regex:"\\b\\w+\\b"The "\\b" matches a word boundary (logical, so it actually doesn't match a character), and the "\\w" matches a word character.-- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
0
Joshua
1/6/2008 7:01:25 PM
On Sun, 6 Jan 2008 03:46:51 -0800 (PST), Roy <royliuk@hotmail.com>wrote, quoted or indirectly quoted someone who said :>>I've tried different ways to write the expression but didn't work this>out. Can anyone help?see http://mindprod.com/jgloss/regex.html -- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
0
Roedy
1/7/2008 12:26:32 PM
On Sun, 06 Jan 2008 19:01:25 GMT, Joshua Cranmer<Pidgeot18@verizon.invalid> wrote, quoted or indirectly quoted someonewho said :>"hello", "hello world",         "1hello-2*hello"if you had a file that looked like that, you could read it as a csvfile.  See http://mindprod.com/jgloss/csv.html-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
0
Roedy
1/7/2008 8:06:41 PM
Reply:

Similar Artilces:

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

Urgent Requirement for """""""""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting ...

Urgent need """""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting Database/ETL requirements (Optional) Data warehousing experience Threading and job concepts in 10g/11g Cost based Optimizer concepts in 10g/11g Must : Experience with XML files and partitioning concepts in Oracle, Collections, Material Views Note : No phone calls please. : send Resumes to karthik@bhaninfo.com Thanks & Regards Karthik BhanInfo karthik@bhaninfo.com ...

Problem beyond "Hello World": "Hello Word"
Hi everybody I�m still working on a program that types to a Word document. My program opens a Word document and shall work if Word is already running or not. The user are able to do anything with the opened document and application: close them or not. I have extracted the problematic lines from my code. This simple program have just a form with a command button: Private sub Command1_Click Dim appl As Word.Application Dim doc As Word.Document On Error Resume Next Set appl=GetObject(,"Word.Application") If Err.Number<>0 Then Set appl=CreateObject("Word.App...

Urgent JAVA Requirement in """"""NEW YORK"""""""""
Hello Partners, How are you ? Please find the requirement below. Location : NY Duration : 8 mnths Rate :Open Job description: Java/J2EE Web Service Developer =B7 (4+ years of application development experience in Java/J2EE and Web service technologies. =B7 Experience with spring & Hibernate. =B7 Experience with J2EE Application Server (preferably Web logic). =B7 Preferable Aqua logic DSP Experience =B7 Preferable Sonic ESB Composite Service experience Experience w...

to print in the reverse order, ("Hello World" -> "World Hello")
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info; struct llnode *next; }; typedef struct llnode NODE; int main() { char msg[50],word[10],*str; int i=0,length=0,j=0; NODE *ptr,*front=NULL,*temp,*last=NULL; printf("Enter the sentence: "); str=fgets(msg,sizeof(msg),stdin); while(str[i]!='\0') { if((str[i]==' ')||(str[i]=='\n')) { ...

A problem about "[ ]" "( )" "="
I want to read several images saved in a director,and give them to I1,I2 ,I3....,using the following codes: filelist=dir(['c:\MATLAB701\work\...\*.jpg']); for i=1 :length(filelist) I=imread(fullfile('c:\MATLAB701\work\...',filelist(i).name)); end; but failed. Then I used I(i)=imread... ,still failed. How could I do? "John" <mailofww@126.com> wrote in message news:ef19e12.-1@webx.raydaftYaTP... >I want to read several images saved in a director,and give them to > I1,I2 ,I3....,using the following codes: > filelist=dir(['c:\MATLAB701\work\.....

Does it need a ";" at the very after of "if" and "for"
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ...

"In" "Out" and "Trash"
I just bought a new computer and I re-installed Eudora Light on my new computer. But when I open Eudora, the "In", "Out" and "Trash" links are not on the left side of the screen the way they were on my old computer. How can I get these links back on the left side of the screen? Thank you. On 25 Mar 2007 09:49:22 -0700, "abx" <abfunex@yahoo.com> wrote: >I just bought a new computer and I re-installed Eudora Light on my new >computer. But when I open Eudora, the "In", "Out" and "Trash" links >are ...

char * ptr = "hello" and char carray[] = "hello"
Consider the following sample code char * ptr = "hello"; char carray[] = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is it a fair statement that char *ptr will take 4 more bytes (on 32bit platform) in DATA segment? I have found the statement true at least with gcc 2.96. I assume under certain condition the compiler can optimize the storage away? Thanks for your comments, Fei "fei.liu@gmail.com" <fei.liu@gmail.com> writes: > Consider the following sample code > > char * ptr =...

puts "\\".gsub("\\", "\\\\")
Hello, I have a mini-ruby quiz. Guess what this line of code writes to the console, then try it for yourself: puts "\\".gsub("\\", "\\\\") Why is that so? Martin From: martinus [mailto:martin.ankerl@gmail.com]=20 # Hello, I have a mini-ruby quiz. Guess what this line of code writes to # the console, then try it for yourself: # puts "\\".gsub("\\", "\\\\") puts "\\".gsub("\\", "\\\\") \ #=3D> nil # Why is that so? faq. escaping the escape in sub/gsub. search the archives. maybe you want somethin...

Gary Sokolich """"""
"""""""""" http://www.manta.com/c/mmlq5dm/w-gary-sokolich W Gary Sokolich 801 Kings Road Newport Beach, CA 92663-5715 (949) 650-5379 http://www.tbpe.state.tx.us/da/da022808.htm TEXAS BOARD OF PROFESSIONAL ENGINEERS February 28, 2008 Board Meeting Disciplinary Actions W. Gary Sokolich , Newport Beach, California �V File B-29812 - It was alleged that Dr. Sokolich unlawfully offered or attempted to practice engineering in Texas (...) Dr. Sokolich chose to end the proceedings by signing a Consent Order that was accepted by ...

Question about "sprintf" "@" "do for"
Hello, this works: A1=3D1 A2=3D2 A3=3D3 i=3D1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari i=3Di+1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari i=3Di+1 vari=3Dsprintf("A%.f",i) print vari,"=3D",@vari do for [i=3D1:3]{ vari=3Dsprintf("A%.f",i) print vari } But I want to have "print vari,"=3D",@vari" in the loop. But it dosen't=20 work. Why can't I use "print vari,"=3D",@vari" in the loop? Is there a=20 solution for? J=C3=B6rg Jörg ...

Automate program execution problem (Runtime.exec("java" + " Hello.java"); #2
I want to automate the program compilation and execution. I used Runtime.exec("javac" +" Hello.java"); for compilation the program compiled successfully. in the next liine i gave Runtime.exec("java" + "Hello"); This statement dosen't performs execution. Anybody knows tell me the solution for this problem By Seenu ...

different between the "::" and "."
Hello, class Myclass def Myclass.hi "hi" end def Myclass::hello "hello" end end what's the difference between Myclass.hi and Myclass::hello here? Thanks. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 11.12.2010 14:25, schrieb zuerrong: > Hello, > > class Myclass > def Myclass.hi > "hi" > end > def Myclass::hello > "hello" > end > end > > what's the difference between Myclass.hi and Myclass::hello here? ...

Web resources about - regular expression to parse {"hello", "hello world", "1hello-2*hello"} - comp.lang.java.programmer

Resources last updated: 2/16/2016 7:33:27 PM