Regular expression to remove vertices and carriage returns and lines from a sentence

Is it also possible to combine this with deleting periods from a row? A sentence may have spaces that I would like to keep.

+7
string regex
source share
2 answers

Search

^[\r\n]+|\.|[\r\n]+$ 

and do not replace anything.

The specific syntax will depend on the language you use, for example. d. in C #:

 resultString = Regex.Replace(subjectString, @"^[\r\n]+|\.|[\r\n]+$", ""); 

in PHP:

 $result = preg_replace('/^[\r\n]+|\.|[\r\n]+$/', '', $subject); 

in javascript:

 result = subject.replace(/^[\r\n]+|\.|[\r\n]+$/g, ""); 

etc...

+9
source share

You can find:

 ^[\r\f]+|[\r\f]+$ 

and replace it with

 '' 

During periods you can find

 \. 

and replace it with

 '' 

Some languages ​​provide you with a function that accepts a group of regular expressions and replacements and performs a replacement in a single function call. Like PHP preg_replace.

+1
source share

All Articles