Reputation: 3501
Working on a script that will parse some of my java files. I am trying to use replaceAll() to get rid of some of the things that I do not need. So of it is static stuff which is easy, but some are harder.
MyWebsiteTests extends MYbaseTest {
So for this one I want to remove the extends and anything after it on that line. Thanks
Upvotes: 3
Views: 2382
Reputation: 171194
This would do it:
line.replaceAll( /(.+)\sextends.*$/, '$1' )
Parsing source code with regex always seems to end in tears though...
Upvotes: 5
Reputation: 43703
Groovy:
assert expected == before.replaceFirst(/\s+extends\s.*/, '')
or
assert expected == before.replaceAll(/\s+extends\s.*/, '')
Upvotes: 2