 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tonne
Joined: 06 Jun 2006 Posts: 1249 Location: Denmark
|
Posted: Thu Aug 23, 2007 2:33 pm Post subject: |
|
|
| Code: | str = _word_ or _word and word_ these
msgbox % regexreplace(str,"_([^_]*)_","[it]$1[\it]") |
_________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Aug 23, 2007 9:22 pm Post subject: |
|
|
that would be great if it would work in indesign but apparently it doesnt
i have to look into it |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Mon Sep 17, 2007 5:19 pm Post subject: |
|
|
I am finally attempting to learn some regex. I am making a listview app as part of an interface at work. I am calculating the priority of a call based on different info.
In this case, I need to tell if the Comments variable contains one of the listed names and also a call ID number (4 - 6 digits). The format is not standardized, and I don't mind a few false positives.
Here is my current regex:
| Code: |
Comments := "ENGUNNEER -- See Call ID #12345"
If RegexMatch(Comments, "i)(BOB|JIM|JON|TOM|ALEX|ENGUNNEER)(?=.*\d{4,6})")
Msgbox Found name and Call ID in comment
|
This appears to work OK, except I would like to filter out numbers longer than 6 digits, and also numbers that have a - touching them. That will let me skip all comments that contain a part number from our system.
This should match:
| Code: |
Comments := "ENGUNNEER -- See Call ID 13554 - Part number Q-12348"
|
These should not match if possible
| Code: |
Comments := "ENGUNNEER -- Please verify Part number Q-12348"
Comments := "ENGUNNEER -- Please verify Part number 51012348"
|
Thanks for any advice _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
edu
Joined: 12 Oct 2006 Posts: 91 Location: Canada
|
Posted: Tue Nov 20, 2007 7:48 pm Post subject: |
|
|
Hi! It seems like your problem is close to mine. I also can't figure out a regex that can deal with this situation:
I want to change some Bible verses reference styles from . to : that would work like this:
change:
Havia 1.000 pessoas lendo Mateus 4.2 e Lucas 3.25-27
to:
Havia 1.000 pessoas lendo Mateus 4:2 e Lucas 3:25-27
Using a sed syntax I had done this:
s/\.([1-9]/:\1/g
but then the 1.000 becomes 1:000
edu _________________ The best things of life are free. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Nov 20, 2007 10:27 pm Post subject: |
|
|
will 1.000 always be the same? will whatever number is there have 2 or less digits after the .? Are there any chapters that have >99 verses? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
edu
Joined: 12 Oct 2006 Posts: 91 Location: Canada
|
Posted: Tue Nov 20, 2007 10:54 pm Post subject: |
|
|
My idea is to have a regular expressions that can substitute the . (period) for : (colon) only when it precedes no more two digits. So 8.50 would be 8:50, but 2.007 would remain the same.
Yes, there is only Psalm 119, that has more than 99 verses. Good reading tho.
For that little exception I wouldn't bother checking it later.
Edu _________________ The best things of life are free. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Nov 20, 2007 11:31 pm Post subject: |
|
|
i don't know the exact syntax, but you can use {min,max} to limit the matching to 1 or 2 digit numbers. {1,2} _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Tue Nov 20, 2007 11:45 pm Post subject: |
|
|
| edu wrote: | | My idea is to have a regular expressions that can substitute the . (period) for : (colon) only when it precedes no more two digits. So 8.50 would be 8:50, but 2.007 would remain the same. | Why not try RegExReplace(str, "(?<=\d)\.(?=\d{1,2}(?:\D|$))", ":") _________________
 |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Wed Nov 21, 2007 12:03 am Post subject: |
|
|
| engunneer wrote: | | I would like to filter out numbers longer than 6 digits |
StringGetLen? |
|
| Back to top |
|
 |
edu as guest Guest
|
Posted: Wed Nov 21, 2007 3:27 am Post subject: |
|
|
Thanks Titan! That worked, but ouch! It will take a while for me to absorb it. I'll take a look into assertions, or whatever it is called.
Edua |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Wed Nov 21, 2007 3:28 am Post subject: |
|
|
are you using the analysis tool? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Dec 04, 2007 12:44 pm Post subject: |
|
|
| engunneer wrote: | | This appears to work OK, except I would like to filter out numbers longer than 6 digits, and also numbers that have a - touching them. That will let me skip all comments that contain a part number from our system. | Example:
| Code: | Test("ENGUNNEER -- Please verify Part number 51012348 NM")
Test("ENGUNNEER -- Please verify Part number Q-12348 NM")
Test("ENGUNNEER -- See Call ID 13554 - Part number Q-12348")
Test("ENGUNNEER -- See Call ID #12345")
Test(comments)
{
If RegexMatch(comments, "i)(BOB|JIM|JON|TOM|ALEX|ENGUNNEER).*?[^\d-](\d{4,6}(?:\D|$))", p)
Msgbox Found name %p1% and Call ID %p2% in comment
}
| I reject "negative" numbers, ie. preceded by a dash. If you have other cases, just ask. I also made sure the number ends the string or is followed by a non-number. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Dec 04, 2007 4:18 pm Post subject: |
|
|
thanks. I will try to work that in to the next release.
Another case that could occur involves numbers such as 135487-1 and a-76542-1. I think the latter is already covered by your regex, but I am not sure on the earlier. however annoying, it still is a valid part number format. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
dash
Joined: 29 Nov 2006 Posts: 53
|
Posted: Sat Dec 08, 2007 2:33 am Post subject: |
|
|
Hi guys,
i need help with parsing clipboard, which contains a list of random URLs.
example:
From that list, i only want to keep links of files with specific extensions (lets say jpg and gif), everything else should be removed.
ive tried it with:
| Code: |
RegExMatch(clipboard, "m)^.*\.(jpg|gif)$", outputX)
|
But that code above only "catches" the first found line that matches the regex pattern... and i have no idea why not the rest. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Sat Dec 08, 2007 3:22 am Post subject: |
|
|
you have to loop the regexmatch, I think.
the non regex version may be good enough
| Code: |
keep =
(
.jpg
.gif
)
stringsplit, keeper, keep, `n, `r
loop, parse, clipboard, `n, `r
{
this_url := A_LoopField
loop, %keeper0%
{
if instr(this_url, keeper%A_Index%)
output_urls .= this_url "`n"
}
}
msgbox %output_urls%
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|