Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

regex - find any last character in line except empty lines

I need to find any last character in line and then add extra text (for example "word"), but without applying this rule to empty lines (no characters in line).

My expression like ([^ ])$ works for empty lines, too.

question from:https://stackoverflow.com/questions/65927307/find-any-last-character-in-line-except-empty-lines

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use

(S[^S
]*)

Replace with $1 word. See proof.

Explanation

--------------------------------------------------------------------------------
  (                        group and capture to 1:
--------------------------------------------------------------------------------
    S                       non-whitespace (all but 
, 
, , f,
                             and " ")
--------------------------------------------------------------------------------
    [^S
]*                 any character except: non-whitespace
                             (all but 
, 
, , f, and " "), '
'
                             (newline) (0 or more times (matching the
                             most amount possible))
--------------------------------------------------------------------------------
  )                        end of 1
--------------------------------------------------------------------------------
  $                        before an optional 
, and the end of the
                           string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...