Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding text until end of line regex

Tags:

java

regex

I'm trying to use regex to find a particular starting character and then getting the rest of the text on that particular line.

For example the text can be like ...

V: mid-voice T: tempo

I want to use regex to grab "V:" and the the text behind it.

Is there any good, quick way to do this using regular expressions?

like image 343
user941401 Avatar asked Oct 24 '11 05:10

user941401


1 Answers

If your starting character were fixed, you would create a pattern like:

Pattern vToEndOfLine = Pattern.compile("(V:[^\\n]*)")

and use find() rather than matches().

If your starting character is dynamic, you can always write a method to return the desired pattern:

Pattern getTailOfLinePatternFor(String start) {
    return Pattern.compile("(" + start + "[^\\n]*");
}

These can be worked on a little bit depending on your needs.

like image 138
Ray Toal Avatar answered Sep 24 '22 10:09

Ray Toal