Jump to content

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

Put here requests of problems with regular expressions


  • Please log in to reply
1074 replies to this topic
sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Haystack :=	"01*02*03*04*05*TEXT1*TEXT2*TEXT3"

Haystack :=	RegExReplace(Haystack,"^.*?\*(?=\D)")	; remove everything up to the first star followed by a non-digit

Loop, parse, Haystack, *	; parse 'Haystack'

	if	A_Index > 2	; only parse the first two stars since the third term might have a star

		break

	else	var%A_Index% :=	A_LoopField

var3 :=	SubStr(Haystack,StrLen(var1)+StrLen(var2)+3)

MsgBox %	var1 "`n" var2 "`n" var3


_Guest
  • Guests
  • Last active:
  • Joined: --
that worked, thanks

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
which regex code represents any zero or more character, I mean ANY character, newline, symbol, digit, ANYTHING


also, \h that represents any whitespace character (space, tab, but not newline, or other) does not seem to work, which is the alternative?

thanks

  • Guests
  • Last active:
  • Joined: --
A dot (.) combined with the s (DotAll) option. Described in doc so don't ask how, why, example etc as it is already in the help file.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Space or tab: [\s\t]

For the any character; use the DOTALL option where you can. Everywhere else I end up using (.|\n).
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
I did not find sufficient documentation for DotAll, but it seems I just need to place (?s) before the dot to enable it

it complicates alot the code (because, first, s is meant for space, second, I dont know where it is enabled and where it is not, third, I need to disable it if I dont want to use it, etc), so, I came up with this, that seems to do the job:

(\t|\n|.|\r)*


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
That's just a less efficient version of (\n|.)*.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008

That's just a less efficient version of (\n|.)*.


OMG !

Your post was the 666th post in this topic ! :twisted:

  • Guests
  • Last active:
  • Joined: --

I did not find sufficient documentation for DotAll, but it seems I just need to place (?s) before the dot to enable it

As there are only three RE related pages in the documentation you must be joking. DotAll is described perfectly, no need for further documentation.

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
I cant make it work:

RunWait, pdftotext -f 1 -l 1 -layout 1.pdf x-timestamp.txt
FileRead, xx, x-timestamp.txt
ClientID := RegExReplace("%xx%" , "sm).*^COMPANY NAME\h+: (.+)$sm).*" , "$1")
FileMove, 1.pdf, %ClientID%.pdf

what's wrong with it?

:?

  • Guests
  • Last active:
  • Joined: --
I'll give you a hint, you can only pass on the options once, you do it twice, why, where is that documented? Do as the docs say, not as your imagination tells you ;-)
RegExReplace("%xx%" , "[color=red]sm)[/color].*^COMPANY NAME\h+: (.+)$[color=red]sm)[/color].*" , "$1")


tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
I'll give you another hint: you don't use %'s in an expression and functions.
RegExReplace("[color=red]%[/color]xx[color=red]%[/color]" , "sm).*^COMPANY NAME\h+: (.+)$sm).*" , "$1")

also, lose the "quotes" around the xx.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
aaarrggghhh it still doesnt work:

RunWait, pdftotext -f 1 -l 1 -layout 1.pdf x-timestamp.txt
FileRead, xx, x-timestamp.txt
msgbox %xx%
ClientID := RegExReplace(xx, "m).*^COMPANY NAME\s+: (.+)$.*", "$1")
msgbox %ClientID%
FileMove, 1.pdf, %ClientID%.pdf

both xx and ClientID are the whole text of the x-timestamp.txt, while it should be only the (.+) of the "sm).*^COMPANY NAME\s+: (.+)$.*"

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
any help with the above?

  • Guests
  • Last active:
  • Joined: --
Make it simple.
Show me your haystack for example.