Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

regex Help



  • Please log in to reply
7 replies to this topic
grimboto
  • Members
  • 13 posts
  • Last active: Jul 17 2014 11:15 PM
  • Joined: 26 Jun 2012
hey im trying to remove some numbers from the beginning of a string using regex but i cant seem to get it working.

651 2 224 foote street

1 2 452 2 224 baker street

14 george street

1 782 2 1 smith street

the numbers i want to keep are the red ones

i came up with this

address := 651 2 224  foote street

Address := RegExReplace(Address, "\d+\s\d") 

but it only works in some situations

any help would be appreciated

Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012
This should work.

String =1 782 2 1 smith street

RegExMatch(String, "(.* |.*?)(\d+?) \w+", _)

MsgBox, %_2%

Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.

 


Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011
I'll give it a shot
data =

(

651 2 224 foote street

1 2 452 2 224 baker street

14 george street

1 782 2 1 smith street

)

loop, parse, data, `n, `r

	out .= RegExReplace(A_LoopField, ".*(\b\d+\b\V*)", "$1") "`n"

MsgBox % out


Gogo
  • Guests
  • Last active:
  • Joined: --
address := 651 2 224  foote street



Address := RegExReplace(Address, "\d+\s[color=#BF0000](?=[/color]\d[color=#BF0000])[/color]")


Gogo
  • Guests
  • Last active:
  • Joined: --
edit:
address := 651 2 224  foote street

Address := RegExReplace(Address, "\d+\s[color=#BF0000]+(?=[/color]\d[color=#BF0000])[/color]")


cka-cka
  • Members
  • 112 posts
  • Last active: Jun 27 2013 05:17 PM
  • Joined: 27 Dec 2011
✓  Best Answer
tested, works for finding the last number before the words
Using RegExMatch:
data =
(
651 2 224 foote street
1 2 452 2 224 baker street
14 george street
1 782 2 1 smith street
)

loop, parse, data, `n,`r
{
    found := regexmatch(a_loopfield,"(?<=(\s))?\d+(\s\D+)",match)
    if found
        matches .= match "`n"
}
msgbox %matches%
Using RegExReplace:
data =
(
651 2 224 foote street
1 2 452 2 224 baker street
14 george street
1 782 2 1 smith street
)

loop, parse, data, `n,`r
	address .= regexreplace(a_loopfield,"(?:.+\s)?(\d+\s\D+)","$1`n")
msgbox %address%


ipottt
  • Guests
  • Last active:
  • Joined: --
if you are trying to match the last digit in your data then

data = 651 2 224 foote street

needle := "(\d+)(?!.*\d)"
Found := RegExMatch(data, needle,var)
if(found)
	msgbox % var


grimboto
  • Members
  • 13 posts
  • Last active: Jul 17 2014 11:15 PM
  • Joined: 26 Jun 2012
thanks for all the help guys cka-cka's solution is working great