-1

i am new to regex and i'm trying to do something :

I want an expression that matchs from one sequence of characters to an other one, that can repeat. For example i have this :

string1 aze string2 eza string3 aze string4 eza string5

And i want to match this

aze string2 aze string4

I have read this : How to match "anything up until this sequence of characters" in a regular expression?

And when i use

aze(.*)*(?=eza)

it matchs

aze string2 eza string3 aze string4 

Can someone help me with this if it's possible ?

Amodos
  • 1
  • 4
  • You link to a question giving you the answer, and then do something different from what's in the stated answer. Perhaps you should do what the answers there tell you to, or if that's giving you a problem, explain what. Nothing there tells you to use `(.*)*`. –  Oct 14 '17 at 14:30
  • ok thanks for your participation – Amodos Oct 16 '17 at 07:54

2 Answers2

1

Here is one that will match any numer of words in between, relying on a reluctant quantifier:

aze.*?(?=\s+eza)

And the demo here.

PJProudhon
  • 835
  • 15
  • 17
0

If you want to match the String following a certain word you can just do this

<word>.(\S+)*
where \S+ --> gives you the next String following your word(in your case `aze`) match.

In your case it becomes something like

aze.(\S+)*

You can test the desired result here:Your output. Also since you are a beginner to Regex for any other quantifier information you can visit in here:

Hope it helps...

  • My case was to simplify, but "string2" and "string4" can contain an indetermined number of word. That's why i want all word until eza in my example – Amodos Oct 14 '17 at 14:25
  • I take your output, and their is my problem https://regex101.com/r/4klhOD/5 i want that it matchs the string "iwantit" and "iwantittoo". In my real case, i don't know the number of words. I just know that i want all words from aze to eza. Ot maybe i miss something. Thanks anyway :) – Amodos Oct 14 '17 at 14:35
  • 2
    Okay cool your question didn't specify that before so meant the thing which I gave. By the way you can simply use the answer mentioned above(**from @PJProudhon**). It works perfectly fine and I would have given the same too(as per your mentioned case) –  Oct 14 '17 at 14:49