Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching and extracting  RSS feed

 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say I have in a variable:

This is an example

more words here
lalalal
lalalal
more stuff here
ssdfsdfWHATIWANTTOEXTRACTsadasd


How could I look for the sentence ssdfsdfWHATIWANTTOEXTRACTsadasd in that example? Then once I get that line I wanted to extract the part that says WHATIWANTTOEXTRACT from ssdfsdfWHATIWANTTOEXTRACTsadasd?

So in the end of all that code I put in a variable "WHATIWANTTOEXTRACT"

Thanks for the help!!
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regular expressions will do the job for you.
They may look complex at first glance, but a few hours of learning will get you started.

The Sun site has a tutorial dedicated to the standard java regex api:

The Apache RE project has an interactive Regular Expression resolver that's ready to run.

The Regular-Expressions.info site has links to tutorials and more.

Regards, Jan
 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone write me a quick example?

All I want it to do is search for something put it in a variable. Then extract something from that variable.



For example I look for <script language="JavaScript" src="http://www.somewhere/ineedthis">

Then I use another method to extract ineedthis from that variable.



Thanks for any help!!!
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone write me a quick example?

All I want it to do is search for something put it in a variable. Then extract something from that variable.


IMHO, regular expressions have an initially relatively high learning curve. It can't really be learned with a quick example. You really should take the time to learn it by going through a good book or website.

Anyway...



Here is what you want as the quick example... hopefully, this will give you an idea of the power of regex, and incentive to learn more about it.

Henry
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slight modification... probably won't affect you, but I'm just being paranoid.



Henry
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can always use the indexOf method in String class by the way...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!