Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Findrx (greedy or back-reference?) problem
#1
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!
#2
if you don't get an answer here, try stackoverflow.com
An old blog on QM coding and automation.

The Macro Hook
#3
Thanks for the site. In the meanwhile, hopefully Gintaras will help here as always!
#4
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.,
#5
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!
#6
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
#7
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!
#8
Look, maybe this will work

Macro Macro1497
Code:
Copy      Help
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
#9
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)