-2

I have one multiline text box. This box contains large string which has new line breaks.I want to display first 10 chars of each line or paragraph in a multiple text. My multiple text box contains more than 100k chars. Is there any best solution to retrieve string using regex?

Example input:

this is sample test
I am from australia
I am from India

The expected output is the first 10 chars of each new line/paragraph followed by ...

this is sam...
I am from a..
I am from I..
James Z
  • 12,209
  • 10
  • 24
  • 44
Jagathish
  • 7
  • 1
  • 2
    Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Dec 11 '16 at 12:51

1 Answers1

1

Try this regex to find the first 10 characters: ^(.{10})(.*)$ and replace with $1...

output = input.replace(/^(.{10})(.*)$/gm, '$0...')
print(output[<line>])

Note this will match I am from␠ instead of I am from a because it counts spaces too.

Nicolas
  • 6,611
  • 3
  • 29
  • 73