When does pressing the Enter (Return) key matter when creating a regex matching expression?

Viewed 46

I want to search for multiple codes appearing in a cell. There are so many codes that I'd like to write parts of the code in succeeding lines. For example, let's say I am looking for "^a11","^b12", "^c67$" or "^d13[[:blank:]]". I am using:

^a11|^b12|^c67$|^d13[[:blank:]] 

This seems to work. Now, I tried:

^a11|^b12|  
^c67$|^d13[[:blank:]] 

That also seemed to work. However when I tried:

^a11|^b12|^c67$|  
^d13[[:blank:]] 

It did not count the last one.

Note that my code is wrapped into a function. So the above is an argument that I feed the function. I'm thinking that's the problem, but I still don't know why one truncation works while the other does not.

1 Answers

I realized the answer today. The problem is that since I am feeding the regex argument, it will count the next line in the succeeding code.

Thus, the code below was only "working" because ^c67$ is empty.

^a11|^b12|  
^c67$|^d13[[:blank:]] 

And the code below was not working because ^d13 is not empty but also this setup looks for (next line)^d13[[:blank:]] instead of just ^d13[[:blank:]]

^a11|^b12|^c67$|  
^d13[[:blank:]] 

So an inelegant fix is:

^a11|^b12|^c67$|  
^nothinghere|^d13[[:blank:]] 

This inserts a burner code that is empty which is affected by the line break.

Related