• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 22
  • 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: 43024
76
  • 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: 22
  • 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
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic