views:

324

answers:

1

Hi ,

i am new to java regular expression.

Consider the follwoing paragraph :

The Internet is a global system of interconnected computer networks that use the standardized Internet Protocol Suite (TCP/IP) to serve billions of users worldwide. It is a network of networks that consists of millions of private and public, academic, business, and government networks of local to global scope that are linked by copper wires, fiber-optic cables, wireless connections, and other technologies. The Internet carries a vast array of information resources and services, most notably the inter-linked hypertext documents of the World Wide Web (WWW) and the infrastructure to support electronic mail. In addition it supports popular services such as online chat, file transfer and file sharing, gaming, commerce, social networking, publishing, video on demand, and teleconferencing and telecommunications. Voice over Internet Protocol (VoIP) applications allow person-to-person communication via voice and video.

The origins of the Internet reach back to the 1960s when the United States funded research projects of its military agencies to build robust, fault-tolerant and distributed computer networks. This research and a period of civilian funding of a new U.S. backbone by the National Science Foundation spawned worldwide participation in the development of new networking technologies and led to the commercialization of an international network in the mid 1990s, and resulted in the following popularization of countless applications in virtually every aspect of modern human life. As of 2009, an estimated quarter of Earth's population uses the services of the Internet.

I need to do the following :

1. To search a given block of text exist For example : Search the follwing block exist

", and other technologies. The Internet carries a vast array of information resources and services, most notably the inter-linked hypertext documents of the World Wide Web (WWW) and the infrastructure to support electronic mail. In addition it supports   popular services such as online chat, "

2. To search a string or block of text exist

For example :

Search the string
  "World Wide Web (WWW) and the infrastructure to support electronic mail. " 
OR search the block of text in above (point 1).

3.Search if the given block of text or string doesn't exist :

For example :
 Follwoing string shouldn't exist :
 Voice over Internet Protocol (VoIP) applications allow person-to-person communication via

4.Search a given word exist or shouldn't exist .

Please help me to resolve the above regular expression.

+2  A: 

Here is a good tutorial for learning how to use regular expressions in Java. In particular, check out the Test Harness, which will allow you to play with different regular expressions and search text.

On the other hand, since the searches you described are not looking for patterns, but rather fixed strings of text, you might find what you need by simply using indexOf(String). Unless the homework assignment is explicitly to use regular expressions...

jheddings
Thanks JHeddings , i agree with you .But indexOf(String) will search for a exact pattern ..here i may give the string with spaces or with quotes .. how to achieve this kind of operations ..i need a common API for which i pass my block and the paragraph .Finally the API should return which contains the specified block or not ..(the block may be set of words , a word ...)
Sidharth