Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression matching in java

Tags:

java

regex

Here is my example file :

lineone one
RUN lineone two
lineone three
RUN lineone four

I want to select all lines not starting with run, here is how I did it :

^([^RUN])

Is it possible to match all lines not starting with RUN and then append them to the back of the previous line ? like this

lineone one RUN lineone two
lineone three RUN lineone four
like image 792
London Avatar asked Jul 13 '26 05:07

London


2 Answers

If your example is correct you just need to replace "\nRUN" with " RUN".

System.out.println(yourString.replaceAll("\nRUN", " RUN"));

Result:

lineone one RUN lineone two
lineone three RUN lineone four

ideone

like image 196
Mark Byers Avatar answered Jul 14 '26 18:07

Mark Byers


use str.startsWith("RUN");

like image 28
jmj Avatar answered Jul 14 '26 18:07

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!