| View previous topic :: View next topic |
| Author |
Message |
TestPilot
Joined: 26 Jun 2007 Posts: 52
|
Posted: Tue Oct 13, 2009 11:37 am Post subject: RegEx works simple case, but not real life |
|
|
I need to match anything that starts with "[[Daten:" and ends with "]]"
Regex that works:
It works on
| Code: | | useful info[[Datei:string to match]]useful info |
but not on
| Code: |
useful info[[Datei:string
something here on a new line
to match]]useful info[[something that don't need to be matched]] something else
|
And i could not figure out way to fix it... |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Tue Oct 13, 2009 12:29 pm Post subject: |
|
|
| Code: | haystack =
(
useful info[[Datei:string
something here on a new line
to match]]useful info[[something that don't need to be matched]] something else
)
needle = m)\[\[Datei:(.*?)]]
RegExMatch(haystack, needle, result)
MsgBox % result1 |
Returns:
| Quote: | string
something here on a new line
to match |
m) = multi-line (optional), in this case it is not necessary. See also the x) option
(.*?) = return everything between the parentheses
HTH |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
Posted: Tue Oct 13, 2009 12:32 pm Post subject: |
|
|
| . (dot) in AutoHotkey Help Regular Expressions (RegEx) - Quick Reference wrote: | | A dot matches any single character (except newline: `r and `n). For example, ab. matches abc and abz and ab_ |
| Code: | variable1=useful info[[Datei:string to match]]useful info
variable2=
(Join`r`n
useful info[[Datei:string
something here on a new line
to match]]useful info[[something that don't need to be matched]] something else
)
Loop 2
MsgBox % RegExMatch(variable%A_Index%,"\[\[Datei:[^]]*?]]")
;So this is not enough to work on `r`n which is included when you use FileRead or Notepad Edit text etc.
MsgBox % RegExMatch(variable2, "m)\[\[Datei:(.*?)]]") |
_________________ AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun  |
|
| Back to top |
|
 |
flak
Joined: 02 Oct 2009 Posts: 283
|
Posted: Tue Oct 13, 2009 1:29 pm Post subject: |
|
|
| . (dot) in AutoHotkey Help Regular Expressions (RegEx) - Quick Reference wrote: | | A dot matches any single character (except newline: `r and `n). For example, ab. matches abc and abz and ab_ |
| s option wrote: | | DotAll. This causes a period (.) to match all characters including newlines (normally, it does not match newlines). |
RegExMatch(variable2, "s)\[\[Datei:(.*?)]]")
No? |
|
| Back to top |
|
 |
TestPilot
Joined: 26 Jun 2007 Posts: 52
|
Posted: Tue Oct 13, 2009 1:52 pm Post subject: |
|
|
| Thanks n-l-i-d, HotKeyIt and flak! It worked somehow |
|
| Back to top |
|
 |
|