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
Gogo
  • Guests
  • Last active:
  • Joined: --
$ matches the end of the line just before new line
. matches any single character (except newline: `r and `n)

$. is impossible pattern and will never match successfully unless s)-option is active

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007

Make it simple.
Show me your haystack for example.


here it is:

unique ID : r533



COMPANY NAME                               : this
PRODUCT DESCRIPTION                        : that
blah blah
blah

$. is impossible pattern and will never match successfully unless s)-option is active


I replaced m) with sm) and still doesnt work

  • Guests
  • Last active:
  • Joined: --
Dude..
You have to specific and persistent.

You posted "Before" part only.
Where is "After" part ?

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007

Dude..
You have to specific and persistent.

You posted "Before" part only.
Where is "After" part ?


for this code:
FileRead, xx, file.txt
ClientID := RegExReplace(xx, "m).*^COMPANY NAME\s+: (.+)$.*", "$1")
msgbox %ClientID%

file.txt (and thus xx, I suppose) contains this:
unique ID : r533



COMPANY NAME                               : SOMECLIENT
PRODUCT DESCRIPTION                        : that
blah blah
blah

the RegExReplace should search for m).*^COMPANY NAME\s+: (.+)$.* which should match all text in file.txt (and thus xx) and it should replace it with $1 which is SOMECLIENT

so it should msgbox SOMECLIENT

Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009
H =

(



																																				unique ID : r533 







COMPANY NAME                               : SOMECLIENT 

PRODUCT DESCRIPTION                        : that 

)																																				

RegExMatch( H, ".*unique ID : (\w*).+COMPANY NAME\s*: (\w*).+PRODUCT DESCRIPTION\s*: (\w*)", var)

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


Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009
You need to study.
Join  ; I mean Join`r`n
and
"s)"  ; in RegEx
further and farther maybe..

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
.*unique ID : (\w*).+COMPANY NAME\s*: (\w*).+PRODUCT DESCRIPTION\s*: (\w*)

---------------------                     -- -----------------------------

           |                               |                |

           |                               |                |-> ; can I replace this with .* to make it match ANY kind of text or nothing afterwards ?

           |                               |-> ; I want to make sure that after (\w*) there the line ends, can I place an [b]$[/b] after [b](\w*)[/b] ?

           |-> ; can I replace this with .* to make it match ANY kind of text or nothing, before [b]COMPANY NAME[/b] ?


  • Guests
  • Last active:
  • Joined: --
You got plenty of hints aleady (actually too much).

Stop asking.

Try it.

Again and again.

Nobody bites you.

Bye.

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
I have tried it and it doesnt work, that's why I am posting it

  • Guests
  • Last active:
  • Joined: --
azure your problem is you try too many things, you need to start and learn and try something in its simplest form.
H=
(join`r`n

     unique ID : r533

COMPANY NAME                               : SOMECLIENT 123
PRODUCT DESCRIPTION                        : that
)
RegExMatch(H, "m)COMPANY NAME\s*: (.*)$", var)
MsgBox % var1
See how easy?

  • Guests
  • Last active:
  • Joined: --
That is really good point.
Make it simple !!
H= 
(join`r`n 

     unique ID : r533 

COMPANY NAME                               : SOMECLIENT 123 
PRODUCT DESCRIPTION                        : that 
) 
RegExMatch( H, "unique ID\s*: (.*)", first ) 
RegExMatch( H, "COMPANY NAME\s*: (.*)", second ) 
RegExMatch( H, "PRODUCT DESCRIPTION\s*: (.*)", third ) 

MsgBox % first1 "`r`n" second1 "`r`n" third1


azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
there are some strange things happening, it's seems I still miss something:

I have written in txt.txt this text:
unique ID : r533

COMPANY NAME                               : SOMECLIENT 123
PRODUCT DESCRIPTION                        : that

I run this:
FileRead, txt, txt.txt
RegExMatch(txt, "m).*^COMPANY NAME\s*: (.*)$.*", var)
MsgBox % var
and it returns
SOMECLIENT 123


I run this:
FileRead, txt, txt.txt
RegExMatch(txt, "m).*^COMPANY NAME\s*: (.*)$.*", $1)
MsgBox % $1
and it returns
COMPANY NAME                               : SOMECLIENT 123


I run this:
FileRead, txt, txt.txt
ClientID := RegExReplace(txt, "m).*^COMPANY NAME\s*: (.*)$.*", "var")
msgbox %ClientID%
and it returns:
unique ID : r533

var
PRODUCT DESCRIPTION                        : that


:shock: :shock: :shock:

are all these expected?

all I want to do is to replace the whole text (txt) with SOMECLIENT

BUT I want to make sure that SOMECLIENT is the correctly selected text, by making sure that it is after ^COMPANY NAME\s+:\s and before $

can you make this work?
I think there is a problem with either expressing correctly the back reference, or by expressing correctly the end of line

  • Guests
  • Last active:
  • Joined: --
Are you a God of RegEx or something ? Many member of here aleady told you that.
Read The F***ing Manual, Please.
$ may appear at the end of a pattern to require the match to occur at the very end of a line....


azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007

Are you a God of RegEx or something ? Many member of here aleady told you that.
Read The F***ing Manual, Please.

$ may appear at the end of a pattern to require the match to occur at the very end of a line....


so which code works for you?

  • Guests
  • Last active:
  • Joined: --
All codes are simply wrong.