The beginning of a line or the beginning of a line?
Beginning and end of line
/^CTR.*$/
/ = delimiter
^ = start of line
CTR = literal CTR $ = end of line
.* = zero or more of any character except a newline
Beginning and end of line
/^CTR.*$/m
/ = delimiter
^ = start of line
CTR = literal CTR $ = end of line
.* = zero or more of any character except the newline character
m = enables multi-line mode, this sets the regular expression to treat each line as a string, so ^ and $ will match the beginning and end of the line
In multi-line mode, you can still combine the beginning and end of a line with \A\Z constant anchors
/\ACTR.*\Z/m
\A = means start of line
CTR = literal CTR .* = Zero or more of any character except the newline character
\Z = end of line
m = enables multi-line mode
So another way to match the beginning of the line would be this:
/(\A|\r|\n|\r\n)CTR.*/
or
/(^|\r|\n|\r\n)CTR.*/
\r = carriage return / old version of the new Mac OS | \n = line-feed / Unix / Mac OS X newline
\r\n = windows newline
Please note that if you are going to use the backslash \ in some line of the program that supports escaping, for example, double quotes php "" , you need to avoid them first
therefore, to run \r\nCTR.* you would use it as "\\r\\nCTR.*"
Timo Huovinen Mar 26 '14 at 18:47 2014-03-26 18:47
source share