Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another Regex question - find LAST match
#1
Hello all!

I have a large text, in which i want to extract the last ' match'

something like this for example:

welcome the user is here
nothing has to be matched from this
welcome i like it here

i want the last match from welcome with everithing in between to here... so this has to be 'welcome i like it here'
The first match between welcome and here is not relevant...

Hope somebody can give me an example or directions

Greetings
#2
Macro Macro1841
Code:
Copy      Help
str s=
;welcome the user is here
;nothing has to be matched from this
;welcome i like it here

str m
if(findrx(s "(?s).*^(welcome(?-s).+here)$" 0 8 m 1)<0) end "not found"
;if(findrx(s "(?:^.*[])*^(welcome.+here)$" 0 8 m 1)<0) end "not found" ;;this also works, don't know which is better
out m

;the * is greedy, ie matches as much as possible, therefore the rest will find the last match
#3
Thanks again!

One more question if i may....

What if the last result is splitted in 2 or more lines? like this:

welcome the user is here
nothing has to be matched from this
welcome i like it
here

And i want the result as earlier.. so 'welcome i like it here' is the final match?

Thanks for your help!
#4
This should work. Not tested.

(?s).*\b(welcome.+here)\b
#5
Hi Gintaras,

I tried your solution, but it doesn't work..

Is something wrong with this?

if(!findrx(text F"(?s).*\b({user}.+?(?s)(Markeer\sals\santwoord|wijzig\sreactie))\b" 0 1|8 output_text))

please help me with this


Forum Jump:


Users browsing this thread: 1 Guest(s)