1

This should be pretty damn simple, but I'm a newb at this. Let's say I'm dealing with a block of text 300+ characters long.

I want a regex string which will find any and all characters AFTER the first 200 characters, all the way to the end ($).

I want to delete everything past the first 200 characters. I'm dumping this data into a spreadsheet and don't need EVERYTHING.

==== update =====

Sorry guys, let be very specific. I'm not really using a programming language. (I'm in the app Ubot) Imagine you have a 300+ text block on a page in Textpad. You hit F8 and do a REPLACE. I check the box REGULAR EXPRESSION.

What would the Regular Expression I would use to FIND the first 200 characters, then REPLACE the remaining with NOTHING. (i.e. delete)

Kit
  • 20,354
  • 4
  • 60
  • 103

4 Answers4

0

I want a regex string which will find any and all characters AFTER the first 200 characters, all the way to the end ($).

This regex matches everything except the first 200 characters:

(?<=^[\s\S]{200})[\s\S]*$

If your regex engine supports \K, you can also do:

^[\s\S]{200}\K[\s\S]*$

I want to delete everything past the first 200 characters

That sounds like you just want to match the first 200 characters, which can be done with this regex:

^[\s\S]{200}
Sweeper
  • 213,210
  • 22
  • 193
  • 313
0

Your second and third paragraphs are kind of contradictory. Try this fork of @RugerSR9's that selects up to 200 characters (your input could be less than that, and I assume you still want it).

^.{0,200}

You may want to look at something other than a regex though, e.g., in pseudo-code, string.Left(200).

Kit
  • 20,354
  • 4
  • 60
  • 103
0

Old question, but I don't see any answers that are specific to the OPs question and it could help others in the future. Make sure the Use POSIX regular expression syntax is turned off in the preferences.

Search for:

^\(.\{0,200\}\).*$

And replace with:

\1

Explanation, this (^\(.\{0,200\}\)) will match upto the first 200 chars from the start of the line and put them into group \1. The remaining (.*$ will match the rest of the chars on the line up until the end. The replacement expression replaces the entire line with the \1 group that was matched.

Bonus if you need it a lot. Record it as a macro and then you can trim your files down with a few mouse clicks.

SephB
  • 617
  • 3
  • 6
0

For that purpose I use the block mode in textpad - there is no need to use regex.

Peter
  • 97
  • 13