REGEX riddle Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: REGEX riddle

03 Feb 2017, 15:49

Code: Select all

RegexMatch("RE: Insured Some e2D84587 Company, new E2D84589 GLPD water damage E23456789 claim in NJ, E2D84587"
	, "\b(E[a-zA-Z0-9]{7})\b", out)
code := out1
Oops, forgot my brackets.
matches will be in out1, out2 etc
Last edited by evilC on 03 Feb 2017, 15:55, edited 1 time in total.
Olegred
Posts: 8
Joined: 01 Aug 2016, 15:23

Re: REGEX riddle

03 Feb 2017, 15:51

kon wrote:

Code: Select all

H := "RE: Insured Some e2D84587 Company, new E2D84589 GLPD water damage E23456789 claim in NJ, E2D84587"
RegExMatch(H, "\bE[a-zA-Z0-9]{7}\b", var)
MsgBox, % var  ; E2D84589

MsgBox % RTrim(RegExReplace(H, "(\bE[a-zA-Z0-9]{7}\b\s?)|.+?", "$1"))  ; E2D84589 E2D84587

OMG , you rock.

Thanks everyone. Sorry for confusion. You are great.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: REGEX riddle

03 Feb 2017, 17:00

Olegred wrote: Thanks for the help. However, even in your example it leaves in "E23456789" which is 9 characters, not 8.
I think you need to re-address your criteria
Olegred wrote:Is shorter or longer than 8 characters
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: REGEX riddle

03 Feb 2017, 17:07

Code: Select all

H := "RE: Elements Insured Some e2D84587 Company, new E2D84589 GLPD water damage E23456789 claim in NJ, E2D84587"
RegExMatch(H, "\bE[a-zA-Z0-9]{7}\b", var)
MsgBox, % var  ; Elements

MsgBox % RTrim(RegExReplace(H, "(\bE[a-zA-Z0-9]{7}\b\s?)|.", "$1"))  ; Elements E2D84589 E2D84587


RegExMatch(H, "\bE[A-Z0-9]{7}\b", var)
MsgBox, % var  ; E2D84589

MsgBox % RTrim(RegExReplace(H, "(\bE[A-Z0-9]{7}\b\s?)|.", "$1"))  ; E2D84589 E2D84587
:HeHe:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: REGEX riddle

04 Feb 2017, 14:06

Olegreddo wrote: You got all my requirements in reverse. Thanks for your code. Can you reverse it? Thanks
It's basically a case of adding in/removing exclamation marks (exclamation points),
which act as NOT operators, so the revised code would be as below,
returning only 'E2345678' from the list:

Code: Select all

q::
vText := "e234567 e2345678 e23456789 E234567 E2345678 E23456789"
vText .= " e_34567 e_345678 e_3456789 E_34567 E_345678 E_3456789"
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
Loop, Parse, vText, %A_Space%
{
vTemp := A_LoopField
if (SubStr(vTemp, 1, 1) == "E") ;check first letter case sensitive
if (StrLen(vTemp) = 8) ;check length
if !RegExMatch(vTemp, "[^A-Za-z0-9]") ;check for any non-alphanumeric characters
vOutput .= vTemp " "
}

vOutput := SubStr(vOutput, 1, -1)
Clipboard := vOutput
MsgBox % "done"
Return

;criteria reversed:
;if !(SubStr(vTemp, 1, 1) == "E") ;check first letter case sensitive
;if !(StrLen(vTemp) = 8) ;check length
;if RegExMatch(vTemp, "[^A-Za-z0-9]") ;check for any non-alphanumeric characters
I've tried to make the script really simple,
in case changes need to be made in future.
It parses through spaces, which means you might
want to replace any punctuation such as commas
and full stops (periods) with spaces
before you begin.

If your text contained 'E2D84587,' or 'E2D84587.', for example,
the punctuation marks would count as non-alphanumeric characters,
and those ID values would not be picked up by the script.

Anyhow there are some great RegEx examples here that I will take a look through!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Olegred
Posts: 8
Joined: 01 Aug 2016, 15:23

Re: REGEX riddle

06 Feb 2017, 21:16

kon wrote:

Code: Select all

H := "RE: Insured Some e2D84587 Company, new E2D84589 GLPD water damage E23456789 claim in NJ, E2D84587"
RegExMatch(H, "\bE[a-zA-Z0-9]{7}\b", var)
MsgBox, % var  ; E2D84589

MsgBox % RTrim(RegExReplace(H, "(\bE[a-zA-Z0-9]{7}\b\s?)|.+?", "$1"))  ; E2D84589 E2D84587

NICE. Thanks a lot
Olegred
Posts: 8
Joined: 01 Aug 2016, 15:23

Re: REGEX riddle

21 Nov 2017, 22:53

Hello, Guys, can you please, help me one more time?

I need RegExMatch for the following:

Delete ALL in the string, except for the word that matches the following:

first first characters MUST be numbers
seventh character is a dash ("-")
three last characters are letter combinations PC or BIU

so, for example, delete all that does not match 14930-BIU or 018310-PC

Thanks
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: REGEX riddle

22 Nov 2017, 12:57

Olegred wrote:.
Does the code below do what you want?

Code: Select all

text = ggggggggggggiii--014930-BIU-------------   ggor             gggggggggg--018310-PC   18310-PC   8310-PC   018310-PI

text := RegExReplace(text, "\d{6}-(PC|BIU)(*SKIP)(*F)|.", "")

text := RegExReplace(text, "BIU|PC", "$0`n")

msgbox, % text
Olegred
Posts: 8
Joined: 01 Aug 2016, 15:23

Re: REGEX riddle

23 Nov 2017, 01:07

Oh, my god, you are the best. It works. Magic.
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: REGEX riddle

23 Nov 2017, 10:49

Olegred wrote:Oh, my god, you are the best. It works. Magic.
I forgoted the "\b" option! The code below is more suitable! (for example, it does not match 1234567-BIU, 1234567-PC, 123456-BIUU or 123456-PCC)

Since you are going to use these codes at work and in case you generate good extra incomes by using them, so don't forget to donate some to those who helped you with the codes, right? (with all the respect, may I say ...!)

Code: Select all

text = -123456-BIU- 1234567-BIU \12345678-BIU ]000000-BIT 111111-BIUU --123456-PC 1234567-PC   12345678-PC  222222-PI  ==333333-PCC

text := RegExReplace(text, "\b\d{6}-(PC|BIU)\b(*SKIP)(*F)|.", "")

text := RegExReplace(text, "BIU|PC", "$0`n")

msgbox, % text

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Joey5, mebelantikjaya and 319 guests