Deleting leading numbers

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Deleting leading numbers

Post by WantToKnow » 30 Sep 2022, 09:40

Hello,

how can I delete leading numbers in a sentence using
RegExReplace?

Code: Select all

;Before:
str1 := "03 This is a test."
str2 := "0345 This is a test.
str3 := "134 This is a test."

;After:
str := "This is a test
Thanks for your help.

sofista
Posts: 645
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Deleting leading numbers

Post by sofista » 30 Sep 2022, 10:01

Not sure about the quotes, so guessing you want to keep them:

Code: Select all

data =
(
"03 This is a test."
"0345 This is a test.
"134 This is a test."
)

For k, v in StrSplit(data, "`n")
	MsgBox, % RegExReplace(v, "^""\K\d+ ")
Addendum: Now, if quotes were used just for assigning strings to variables, then the regular expression would be simpler:

Code: Select all

str1 := "03 This is a test."
MsgBox, % RegExReplace(str1, "^\d+ ")

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: Deleting leading numbers

Post by Chunjee » 30 Sep 2022, 12:31

https://biga-ahk.github.io/biga.ahk/#/?id=replace should help.

Code: Select all

A := new biga() ; requires https://github.com/biga-ahk/biga.ahk

str1 := "03 This is a test."
str2 := "0345 This is a test."
str3 := "134 This is a test."
regexpattern := "/^\d+\s/"

msgbox, % A.replace(str1, regexpattern)
; => "This is a test."
msgbox, % A.replace(str2, regexpattern)
; => "This is a test."
msgbox, % A.replace(str3, regexpattern)
; => "This is a test."

Post Reply

Return to “Ask for Help (v1)”