Posts: 13
Threads: 3
Joined: Sep 2008
Hello,
Been reading here and qm help but seems I just can't get some aspects of regular expression syntax.To simplify what I want to do, suppose:
str Sample="abcdefghiklbwxyz"
There are two "b" above. I want to find a match that starts with "b", ends with "yz" but has no "f" in the middle (so the commands below give "11" not "1").
int Look=findrx(Sample "(?=b).+(?!f)(?=yz)")
out Look
Many thanks in advance!
Posts: 1,769
Threads: 410
Joined: Feb 2003
if you don't get an answer here, try stackoverflow.com
Posts: 13
Threads: 3
Joined: Sep 2008
Thanks for the site. In the meanwhile, hopefully Gintaras will help here as always!
Posts: 12,087
Threads: 142
Joined: Dec 2002
QM regular expression syntax is almost the same as in most other languages and applications. Google for help.
Quote:but has no "f" in the middle
maybe use this for the middle:
[^f]+?
It means any number of characters other than f. Maybe will not work , don't know.,
Posts: 13
Threads: 3
Joined: Sep 2008
That actually works, thanks!
However, I wanted this to work with more than a single character. So to slightly change the above requirement, we want something with "bc", ending in "yz" and having no "fgh" anywhere in the middle.
So, to play around with your suggestion
[^f][^g][^h]+? in the middle wouldn't work as the + applies only to h.
(?!fgh)+? in the middle also gives an error.
If you don't know, you said, do you think I should go to the above site (or somewhere else) to look for a solution?
Many thanks!
Posts: 12,087
Threads: 142
Joined: Dec 2002
If no "fgh" as a character set, use [^fgh]+?
If no "fgh" as exact substring, with my knowledge of regular expressions it is not possible. Then also need to use another function, eg find().
stackoverflow is one of the best, and it is usually in the first page of google search results, for whatever
Posts: 13
Threads: 3
Joined: Sep 2008
Yeah, I meant "fgh" as an exact substring. Pity it looks that it's not possible, I'll try to find a workaround.
Thanks for the quick replies and help!
Posts: 12,087
Threads: 142
Joined: Dec 2002
Look, maybe this will work
Macro
Macro1497
str s
;s="abcdefghijyz" ;;does not match
s="abcdefgijyz" ;;match
out findrx(s "bc(.(?!fgh))+?yz")
(.(?!fgh))+?
any character not followed by "fgh", repeat one or more times
Posts: 13
Threads: 3
Joined: Sep 2008
Yesssss, that works!
Strange though, I wonder if the last "?" is necessary, it seems that no matter what string I try, the results are always the same whether I include the last "?" or not.
Anyway, many thanks again!