• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can we search a name with a regex like "%" in a list of values

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a severe, error while implementing with regex "%" followed by a name to search like "%srin" for example:
Code: -
List l = new ArrayList();
l.add("srinivas");
l.add("Sridharsrinivas");
l.add("manojsrinivas");
l.add("abc");


How can i able to implement by searching like %srin should give me the whole contents that are available.
Help me please,
I am awaiting for your replies guys,

Thanks,
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean that it should return all the strings which contain "srin" string in it? If yes, following is the code which does the same:

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the '%' supposed to do - does it just mean there can be any prefix to the 'srin'? If so, no regexp is necessary - plain old String.indexOf should do nicely.
 
soma lingam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
% is nothing to do with that just only a one regular expression
after what ever we give the value it has to be checked
 
reply
    Bookmark Topic Watch Topic
  • New Topic