Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Findrx (greedy or back-reference?) problem

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!
if you don't get an answer here, try
An old blog on QM coding and automation.

The Macro Hook
Thanks for the site. In the meanwhile, hopefully Gintaras will help here as always!
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:


It means any number of characters other than f. Maybe will not work , don't know.,
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!
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
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!
Look, maybe this will work

Macro Macro1497
Copy      Help
str s
;s="abcdefghijyz" ;;does not match
s="abcdefgijyz" ;;match
out findrx(s "bc(.(?!fgh))+?yz")

any character not followed by "fgh", repeat one or more times
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!

Forum Jump:

Users browsing this thread: 1 Guest(s)