Help with Basic Regular Expression Search

  • OK, folks, I’ve never used regular expressions before and it’s high time I started.

    I’m trying to edit a large txt file that has text at the end of many lines that I want to completely remove. I was able to build a search expression to remove text (actually replace it with other text) at the beginning of the lines, but, removing the ending text is proving to be a bit more difficult. I’m sure there’s a way to do it via regexp but I’m not seeing it.

    Each of the lines I want to edit has the same text in the middle of the line. I want to remove that text and the rest of the text all the way to the end of the line, preserving the CR/LF.

    Any suggestions?

    Thanks in advance!


  • You should describe your request more clearly, better give some examples. Then we’ll be easier to help you.

  • This is actually much more clear than most posts asking for regex help.

    You can use a regex like: some text.*?$

    The important part here is the .*?$ at the end which will match the text after “some text” all the way right up until it reaches the end of the line (which is what the $ represents).

    Keep in mind that if your “some text” has special characters in it such as a period, parenthesis, etc then you will need to escape the character.

  • So Dail, that worked! Thank you!

    In the best Reddit practice, I upvoted your response, but, does this site have the equivalent of Karma or gold?

    Best to you and yours!


  • @Marshall-Medoff

    does this site have the equivalent of Karma or gold?

    I’m not really sure how the reddit system works. The reputation here doesn’t really have much value, I think mostly just to weed out spam accounts.

Log in to reply