Skip to content
jehna edited this page Jul 20, 2013 · 3 revisions

Description: Mark the expression to start at the beginning of the line.

Example: The following adds string "Newline:" to the beginning of each line

var lorem = "Lorem ipsum\nDolor sit amet"
lorem = VerEx().startOfLine().replace( lorem, "Newline: " );

/* Outputs:
Newline: Lorem ipsum
Newline: Dolor sit amet
*/

Example: The following adds line numbers to the beginning of each line

var lineNumber = 1;
var lorem = "Lorem ipsum\nDolor sit amet"
lorem = VerEx().startOfLine().replace( lorem, function() { return lineNumber++ + ". "; } );

/* Outputs:
1. Lorem ipsum
2. Dolor sit amet
*/

Example: You can also use the function as a part of any Verbal Expression chain. The following replaces only the strings that start from the beginning of the line:

var lorem = "Lorem ipsum\nAnother Lorem ipsum";
lorem = VerEx().startOfLine().then( "Lorem ipsum" ).replace( lorem, "This gets replaced" );

/* Outputs:
This gets replaced
Another Lorem ipsum
*/

.startOfLine( enable )

Description: Enable or disable the expression to start at the beginning of the line.

Parameter Description
Boolean enable (optional) Enables or disables the line starting. Default value: true

Example: The following example first creates an expression to firest replcae all strings that begin with specifiesd string. Afterwards, the expression is reused to apply strings anywhere in the string.

var lorem = "Lorem ipsum\nThen comes Lorem ipsum";

var expression = VerEx().startOfLine().then( "Lorem ipsum" );
lorem = lorem.replace( expression , "First replacement" );

expression.startOfLine( false );
lorem = lorem.replace( expression , "second replacement" );

/* Outputs:
First replacement
Then comes second replacement
*/
Clone this wiki locally