Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to insert a dash before the final character?

Tags:

regex

Totally new at this and no search has been able to help me.

Trying to turn:

Jan104aca

Into:

Jan104ac-a

/(?<=.)(?!$)

Gets me to every space, just not sure how to isolate the final space

Thanks!

like image 919
Dennis K. Avatar asked Dec 17 '25 12:12

Dennis K.


1 Answers

You can try:

(.*)(.)

and substitute it for:

\1-\2

Regex demo.

like image 58
Andrej Kesely Avatar answered Dec 19 '25 07:12

Andrej Kesely