Note. . It is assumed that you have one line and you want both actions to be applied if necessary (i.e. the second does not depend on the first); if this is not what you want, you need to clarify the issue.
Doing this with one regex makes things unnecessarily ugly (and therefore less maintainable) - here is a way to do this with two:
Input.replaceFirst('\s+L(?=\n)','').replaceAll('(?<=\n)L\w+\s+','')
The first expression removes L (and previous spaces) from the first line (and since we use replaceFirst, only the first line).
The second expression deletes all L-words at the beginning of the line (except for the first line, which does not have a new line before it).
(Since in both cases we will always have a \s+ match, there is no need for an explicit \b , you can use it instead if you do not want deleted spaces to be removed.)
If you prefer to do this using the CFML return function, the equivalent will look like this:
rereplace( rereplace(Input,'\s+L(?=\n)','') , '(\n)L\w+\s+' , '\1' , 'all' )
Personally, I find the other way more readable.
source share