tags:

views:

75

answers:

2

Also is it possible to combine this with removing periods from within the string? The sentence may have spaces which I'd like to keep.

A: 

You can find:

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

and replace it with

''

For the periods you can find

\.

and replace it with

''

Some languages provide you with function what take a a group of regex and replacements and do the replacement in one call to the function. Like the PHP's preg_replace.

codaddict
Is there any reason you're matching `\f` (form feed) instead of `\n` (line feed)?
Max Shawabkeh
+2  A: 

Search for

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

and replace with nothing.

The specific syntax will depend on the language you're using, e. g. 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...

Tim Pietzcker