• 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

Regex - Get all text before a string value and remove bracket

 
Greenhorn
Posts: 2
Eclipse IDE Python Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get the text before a string value and remove the bracket.
Example -

So here, value will be CV.
Now I want to get all the text before result1 and remove openning bracket. In this case, it is all the text before "(CV".
That is "A simple but popular solution to this is to use cross validation". How can I do that?
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dakshila Kn wrote:I want to get the text before a string value and remove the bracket.
Example -

So here, value will be CV.
Now I want to get all the text before result1 and remove openning bracket. In this case, it is all the text before "(CV".
That is "A simple but popular solution to this is to use cross validation". How can I do that?



myString.substring(0,myString.indexOf(" (CV)");
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My advice would be to not do it all in one huge, complicated step - be it a single regex or a chain of method calls.

What's wrong with finding the position of CV, taking the substring to that point, then cleaning off what you still don't want? It's easier to go back and modify it later if the '(' becomes a '[' or such.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic