http://qs321.pair.com?node_id=912020


in reply to Re^2: How to substitute something from only between two specified charecters (sub_question)
in thread How to substitute something from only between two specified charecters

I wrote the regex that way to have an explicit boundary between the second field and the spacing separating it from the third field. I didn't want to eat any extra spacing.

I could have accomplished this in one of three ways:

  1. 1) Explicitly specify that the field shouldn't contain a space at the end like I did. (.*\S)\s+
  2. 2) Use an explicit boundary like (.*)\b\s+
  3. 3) Or rely on non-greedy matching: (.*?)\s+ Which would work because of the hard boundaries for the other fields

In the end, the third method above would probably appear the cleanest, but they all accomplish the same thing in the context of the rest of the regex.

  • Comment on Re^3: How to substitute something from only between two specified charecters (sub_question)
  • Select or Download Code